Hello,
I have an issue with VBA where I am using the Connection.Execute method to add a table to my database. When I go to run the code the table is not being added to the TableDefs collection. However, when I hit the save command in the VBE or I open and close the Navigation Pane the table gets added to TableDefs! DoCmd adds the table just fine to the TableDefs. Can anyone help? Below is the code
I have tried everything from TableDefs.Refresh to RefreshDatabaseWindow, but have had no such luck.
I have an issue with VBA where I am using the Connection.Execute method to add a table to my database. When I go to run the code the table is not being added to the TableDefs collection. However, when I hit the save command in the VBE or I open and close the Navigation Pane the table gets added to TableDefs! DoCmd adds the table just fine to the TableDefs. Can anyone help? Below is the code
Code:
Dim conn As ADODB.Connection, strConn As String
Set conn = New ADODB.Connection
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & CurrentDb.Name
conn.Open strConn
with conn
' This is the code that I want to use to create a new table from an existing table
' but the code does not add to Access until I Save the code or hide/unhide the Nav Pane
.Execute "SELECT * INTO tbl_test1 FROM tbl_test_data", , adCmdText
End With
conn.Close
Set conn = Nothing
End Sub
I have tried everything from TableDefs.Refresh to RefreshDatabaseWindow, but have had no such luck.