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:
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…
How to send bulk emails from outlook using excel VBA? Have you ever felt the need of an Excel based VBA tool or code which can help you to draft Outlook emails in bulk by…
This Excel VBA Code converts the excel range into HTML and also can convert Excel to HTML Table to paste data on Outlook Email Body
To ensure that your VBA project works smoothly without any error, you need to put lot of error handlers and validations. Here is one of them, below code can be used to check if the given path is valid or not. You just need to provide the path of the file to the function and it will check if the file exist at the location. If it returns True that means the file is available at the path, if it returns False that means it is invalid path or the file does not exist at the location.
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…
Custom Calendar Control for MS Access MS Access by default provides inbuilt functionality to pick dates using calendar control; however it lacks few basic functionalities which makes selecting a date bit difficult. For example, if…