In MS Access, the best way to create a multiuser tool is to divide your solution. One part acts as interface and other one acts as database. You can have multiple copies of the interface distributed to users which are connected to central MS Access database saved at common shared drive. To connect the interface to database, you can use link table feature (Access>External Data>Import & Link) available in MS Access. Below is a commonly required VBA code which helps the developers to re-link MS Access linked tables when the database is renamed or moved to other location
'This function loop through all linked tables in MS Access database
'and re-link them to new database path
Public Function UpdateLinkTables()
'
Dim strPath As String
Dim objDatabase As Object
Dim tblDef As TableDef
'
strPath = "E:\Work\ExcelSirJi\Database.accdb"
'
'Set the object to current database
Set objDatabase = CurrentDb
'
'Go through each table in the database and check if it is linked table
'if yes, then update new database path
For Each tblDef In objDatabase.TableDefs
If tblDef.SourceTableName <> "" Then
'If it is hidden table then make it a visible table
tblDef.Properties("Attributes").Value = 0
'Change the database path to new path
'if database requires password then you can un-comment password section in below code
tblDef.Connect = ";DATABASE=" & strPath '& "; PWD=1234"
'Refresh the table
tblDef.RefreshLink
End If
Next
'
'Close the objects
Set tblDef = Nothing
Set objDatabase = Nothing
'
End Function
5. In the above code I have hardcoded new database path in strPath variable but you can make this variable as input parameter of the function by making below changes highlighted in the screenshot (Red are deletion, Yellow are addition):
Hope you liked this article !!
Subscribe our blog for new amazing excel tricks.
Click to below for some more interesting tricks and learning:
Please leave your valuable comments in Comments section:
VBA Code To Change Cell Color Excel supports more than 16 million colors in a cell; hence you should know how to set the exact color in a cell. To do this, you can use…
VBA Code To Add New Sheet In VBA, it is sometime important to add a worksheet at the right place in the Excel. Here is a simple an effective code that adds a new worksheet…
VBA Code to Filter Data in Excel Here is an easy reference code which filters data in the sheet. In the code, we have filtered the data in three steps. Step 1:Â Remove existing filter from…
Learn how to write your first VBA macro in Excel to automate repetitive formatting tasks across multiple worksheets. This beginner-friendly guide will walk you through the process step-by-step, from recording your actions to customizing the code for your specific needs.
VBA code that will sum cells by its color through excel function. This code will really help in making the analysis and presentation better.
How to use VBA to open Workbook in Excel? There are few VBA codes which are commonly used by every developer. One of them is giving an option to user to browse a file. Below is a…