J
John G.
I'm getting an Access Application object error after creating a table in
ADOX. Looks like Access needs to be told to recognize the new table,
'Test2'. When and how should this be done?
1. Create a table (e.g. 'Test2') in an Access .Mdb via ADOX in VBA sub
Dim oConn As New ADODB.Connection
Dim oCatalog As New ADOX.Catalog
Dim oTable As New ADOX.Table
Dim oCol As New ADOX.Column
' connection string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
<full path to .Mdb>
' set Catalog connection to .Mdb
' set up columns in Column objects
' append Column objects to Table object
' append Table object to Catalog object
' everything looks OK in debugger windows
' close all objects & set = Nothing
2. Create an Access Application object in later VBA sub
Dim moAccess As Access.Application ' MS Access application object
Set moAccess = CreateObject("Access.Application")
moAccess.OpenCurrentDatabase <full path to .Mdb>
3. Use DoCmd.RunMacro in later VBA sub to run a Access macro which runs a
series of Access queries.
moAccess.DoCmd.RunMacro sMacroName ' run the Access macro
4. First Access query run via the macro returns error message:
"The Microsoft Jet database engine cannot find the input table or query
'Test2' ..."
In the Access database window, Table 'Test2' is not visible until the window
is refreshed (F5). After
that, the query will run.
ADOX. Looks like Access needs to be told to recognize the new table,
'Test2'. When and how should this be done?
1. Create a table (e.g. 'Test2') in an Access .Mdb via ADOX in VBA sub
Dim oConn As New ADODB.Connection
Dim oCatalog As New ADOX.Catalog
Dim oTable As New ADOX.Table
Dim oCol As New ADOX.Column
' connection string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
<full path to .Mdb>
' set Catalog connection to .Mdb
' set up columns in Column objects
' append Column objects to Table object
' append Table object to Catalog object
' everything looks OK in debugger windows
' close all objects & set = Nothing
2. Create an Access Application object in later VBA sub
Dim moAccess As Access.Application ' MS Access application object
Set moAccess = CreateObject("Access.Application")
moAccess.OpenCurrentDatabase <full path to .Mdb>
3. Use DoCmd.RunMacro in later VBA sub to run a Access macro which runs a
series of Access queries.
moAccess.DoCmd.RunMacro sMacroName ' run the Access macro
4. First Access query run via the macro returns error message:
"The Microsoft Jet database engine cannot find the input table or query
'Test2' ..."
In the Access database window, Table 'Test2' is not visible until the window
is refreshed (F5). After
that, the query will run.