This code runs from a form in DB1, correctly creating the tmakRecentOrders table in another db, Northwind db; however, the DoCmd.DeleteObject statement returns an error saying the tmakRecentOrders tables is not found. It appears that the DoCmd is looking for the table in DB1, not in Northwind. Can you tell me why?
Private Sub cmdExecute_Click()
Dim wks As Workspace
Dim dbs As Database
Dim qdf As QueryDef
Dim strSQL As String
Dim tdf As TableDef
Set wks = Workspaces(0)
Set dbs = wks.OpenDatabase(cDBNAME)
strSQL = “SELECT Orders.*, * INTO tmakNewOrders FROM Orders WHERE OrderDate>#1/6/96#;”
Set qdf = dbs.CreateQueryDef(“”, strSQL) ‘Took out name of query
‘Execute a make-table query to produce the tmakRecentOrders table
qdf.Execute
For Each tdf In dbs.TableDefs
Debug.Print “Table Name: ” & tdf.Name & vbTab & vbTab & _
“Attributes: ” & tdf.Attributes
Next tdf
DoCmd.DeleteObject acTable, “tmakRecentOrders”
dbs.Close
End Sub
Thanks