Sometimes a Microsoft Access database user may find it desirable to automate the process of importing tables from an external Access database file into their current database. Below is a segment of code that provides an example of how to accomplish this.
‘*******CODE*******
Dim root As String
Dim srcDB As database
Dim tdf As TableDef
Dim x As Integer
Root = “C:”
Set srcDB = OpenDatabase(root)
For Each tdf In srcDB.TableDefs
x = 0
If (tdf.Name = “CULVERT”) Then
DoCmd.TransferDatabase acImport, “Microsoft Access”, root, acTable, “CULVERT”, “CULVERT”
errorCheck = 1
End If
Next tdf
‘******************
After the variable declarations, the first line of code sets the variable “root” equal to “C:” which is the location of the external database holding the tables we wish to import. The next line sets our database variable equal to the external database. The next lines of code search through the external database to find the table named “CULVERT.” If this table is found, the table is imported using the DoCmd function. The “acImport” variable simply tells the function that we wish to import information from the database. “Microsoft Access” specifies the type of database containing the table. Following that is the folder location (“root”) of the external database. The variable actable specifies that the object we wish to import is a table. The next two strings contain the table name to import and the name to assign to the imported table when it is imported into the current database. It should be noted that if the table named to be imported already exists in the current database, MS Access will automatically rename the table being imported.
Once the desired tables have been imported, they can be utilized just like any of the other tables in the database.
Related posts:
- Ms Access Databases Don’t Have to Look Unprofessional by Nicholas Brown Over the years I have noticed that a large number...
- MS Access malfunctioning while saving changes in Access Database Form An effective and straightforward way to enter data into the...
- Records Mismatch in Microsoft Access database Indexes created in MS Access enable you to search and...
- Error Message after repairing the MS Access database Access database users may encounter certain error messages while accessing...
- Error Message When You Open An Object In Access Database MS Access database corruption can occur due to various reasons...
Related posts brought to you by Yet Another Related Posts Plugin.
Leave a Reply