I am using a large Excel *.xlsx table to create a MS Access *.accdb Database, including some queries. This provides a final *.accdb file with functionalities to serve the user with a maximum convenience.
Therefore I would like to provide some VBA code in a module, running multiple queries after another.
Long story short: How can I create a Module FROM a VBA script in a MS-Excel *.xlsx file and append it to a MS-Access *.accdb file via VBA?
I found this related post From MS Excel VBA, create a Standard Module in MS Access
This lead me to the solution how to create a blank module in my destination file
'REQUIRES: MS Access 12.0 Object Library
Dim ObjAccess As Access.Application
Dim strPath As String
strPath = "C:\Temp\MyDB_DEV_1.MDB"
Set ObjAccess = New Access.Application
With ObjAccess
.OpenCurrentDatabase strPath, True
.DoCmd.RunCommand acCmdNewObjectModule
.DoCmd.Save acModule, "Module1"
.DoCmd.Rename "MyCodedModule", acModule, "Module1"
.CloseCurrentDatabase
.Quit
End With
Set ObjAccess = Nothing
How can I now retreive this blank module "MyCodedModule" from this file, to add lines of code like
Dim m as DAO.Module
Set m = GetModuleFromDataBase("MyCodedModule") 'HOW?
m.AddFromString "Sub foo()" & vbCrLf & _
" Debug.Print ""FOO""" & vbCrLf & _
"End Sub"