I am trying to import tables using an odbc connection on a periodic basis. I don't want to create a second copy of the tables, so I have to delete them all before doing the import. I found another question similar to this and tried the following code, but it doesn't work.
Private Sub btnPBGUpdate_Click()
Dim TblName As String
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for closed Tables.
For Each obj In dbs.AllTables
TblName = obj.Name
If obj.IsLoaded = False Then
' Delete the tables.
If Not (Left(TblName, 4)) = "MSys" Then
Access.DoCmd.DeleteObject acTable, obj.Name
Else
End If
Next obj
End Sub
I get a compile error Next without For. I am very new to this, so I really don't know what I am doing and would appreciate any help. Thanks.