dev-resources.site
for different kinds of informations.
Import objects from another database in Access VBA
Published at
11/9/2024
Categories
vba
Author
0meow0
Categories
1 categories in total
vba
open
Author
6 person written this
0meow0
open
Introduction
This article covers the ways for importing Tables, Queries, Modules, Forms and Reports in Access VBA.
Import Tables, Queries, Modules, Forms and Reports
Public Sub ImportAllObjects(ByVal filePath As String)
Dim currentTable As TableDef
Dim currentQuery As QueryDef
Dim dc As Document
Dim dbs As DAO.Database
Set dbs = OpenDatabase(filePath)
'Import Tables except System Tables
For Each currentTable In dbs.TableDefs
If Left(currentTable.Name, 4) <> "MSys" Then
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acTable, currentTable.Name, currentTable.Name, StructureOnly:=False
End If
Next
'Import Queries
For Each currentQuery In dbs.QueryDefs
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acQuery, currentQuery.Name, currentQuery.Name
Next
'Import Modules
For Each dc In dbs.Containers("Modules").Documents
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acModule, dc.Name, dc.Name
Next
'Import Forms
For Each dc In dbs.Containers("Forms").Documents
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acForm, dc.Name, dc.Name
Next
'Import Reports
For Each dc In dbs.Containers("Reports").Documents
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acReport, dc.Name, dc.Name
Next
dbs.Close: Set dbs = Nothing
RefreshDatabaseWindow
End Sub
Import Tables
Public Sub ImportTables(ByVal filePath As String)
Dim currentTable As TableDef
Dim dbs As DAO.Database
Set dbs = OpenDatabase(filePath)
'Import Tables except System Tables
For Each currentTable In dbs.TableDefs
If Left(currentTable.Name, 4) <> "MSys" Then
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acTable, currentTable.Name, currentTable.Name, StructureOnly:=False
End If
Next
dbs.Close: Set dbs = Nothing
RefreshDatabaseWindow
End Sub
Import Queries
Public Sub ImportQueries(ByVal filePath As String)
Dim currentQuery As QueryDef
Dim dbs As DAO.Database
Set dbs = OpenDatabase(filePath)
For Each currentQuery In dbs.QueryDefs
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acQuery, currentQuery.Name, currentQuery.Name
Next
dbs.Close: Set dbs = Nothing
RefreshDatabaseWindow
End Sub
Import Modules
Public Sub ImportModules(ByVal filePath As String)
Dim dc As Document
Dim dbs As DAO.Database
Set dbs = OpenDatabase(filePath)
For Each dc In dbs.Containers("Modules").Documents
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acModule, dc.Name, dc.Name
Next
dbs.Close: Set dbs = Nothing
RefreshDatabaseWindow
End Sub
Import Forms
Public Sub ImportForms(ByVal filePath As String)
Dim dc As Document
Dim dbs As DAO.Database
Set dbs = OpenDatabase(filePath)
For Each dc In dbs.Containers("Forms").Documents
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acForm, dc.Name, dc.Name
Next
dbs.Close: Set dbs = Nothing
RefreshDatabaseWindow
End Sub
Import Reports
Public Sub ImportReports(ByVal filePath As String)
Dim dc As Document
Dim dbs As DAO.Database
Set dbs = OpenDatabase(filePath)
For Each dc In dbs.Containers("Reports").Documents
DoCmd.TransferDatabase acImport, "Microsoft Access", filePath, acReport, dc.Name, dc.Name
Next
dbs.Close: Set dbs = Nothing
RefreshDatabaseWindow
End Sub
vba Article's
30 articles in total
mala direta usando o VBA, Excel e Word tudo juntos
read article
Custom Inventory Management System Using VBA: A Cost-Effective Solution for Small Businesses
read article
Import objects from another database in Access VBA
currently reading
Excel 基礎 Part 03 -- 作成したマクロ関数を開発タブから実行する
read article
Validate date format in VBA
read article
Connect MS Access to SQL Server using ADO
read article
Calculate elapsed time in milliseconds in VBA
read article
Word VBA 刪除所有圖形
read article
How to implement a Polar Area Chart using VBA
read article
Automating Excel with Power: Building Your Own Plugin using VBA
read article
Outputting data without using a loop
read article
How to do Excel table association – You are out if you know only VLOOKUP
read article
SPL XLL Practice: Almighty Text Splitting in Excel
read article
SPL XLL Practice: Excel Interval Association
read article
Excel Advanced Group and Summary Method
read article
How to Automatically Extract Eligible Rows in Excel
read article
Set operations of Excel inter row data (intersection, union, difference)
read article
Power Apps - VBA Subs and Functions
read article
Hello there ..im looking for help from someone who has knowledge about VbA
read article
How to Merge Excel Sheets Horizontally
read article
What Programming Language Should Business People Learn?
read article
Looking for Advanced Excel, VBA & Macros Course in Mumbai
read article
How to Save Multiple Excel Files into the Same Folder
read article
New 64-bit IDE for VB6 developers,Twinbasic VisualFreebasic
read article
Streamlining Your Work with Custom Excel Functions
read article
Separação de conteúdo em arquivos no Microsoft Excel
read article
在 VBA 中讀取 UTF8 編碼的文字檔
read article
VBA and Excel as an office GUI.
read article
Send an SMS Message From an Excel Spreadsheet
read article
在 Office VBA 使用 Open AI API
read article
Featured ones: