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 to Browse Outlook Folder Outlook is most commonly used emailing application used in the world. Many people spend their entire day on Outlook applications to read and respond to emails. To automate certain rule-based…
How to Find Duplicate Files In excel using VBA? Yesterday I was working on my computer and cleaning the drives to make some more space. I was surprised to see so many files saved at…
VBA Code to send Outlook Emails Sending bulk emails is a very common activity, there are many office activities that need a person to send bulk emails to single or multiple recipients. You also may…
How to Export Access Data to Excel using VBA Code? Creating a VBA tool in MS Access is always better as compare to MS Excel. MS Access provides better user interface and ability to handle…
Have you ever got into situation in office where you need to count the cells in Excel sheet with specific color? If yes then you can use following code which counts the number of cells…
What is the Usage of sheet color in Excel? When we prepare a report or a dashboard it is easy to identify or analyze reports with a change of color sheet tabs. Analysts generally give…