Application.RefreshDatabaseWindow doesn't always work.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use the following code to check for the existence of a table, and drop it
if True:

Application.RefreshDatabaseWindow

For Each obj In dbs.AllTables
If obj.Name = strTable Then
If obj.IsLoaded = True Then
DoCmd.Close acTable, strTable, acSaveNo
End If
CurrentProject.Connection.Execute _
"DROP TABLE " & strTable
DoEvents
Exit For
End If
Next obj

Why should this be giving me the message, "Cannot drop the table [name],
because it does not exist in the system catalog"? If it didn't exist, the
..Execute line should not have been reached!
 
Allen_N said:
I use the following code to check for the existence of a table, and drop it
if True:

Application.RefreshDatabaseWindow

For Each obj In dbs.AllTables
If obj.Name = strTable Then
If obj.IsLoaded = True Then
DoCmd.Close acTable, strTable, acSaveNo
End If
CurrentProject.Connection.Execute _
"DROP TABLE " & strTable
DoEvents
Exit For
End If
Next obj

Why should this be giving me the message, "Cannot drop the table [name],
because it does not exist in the system catalog"? If it didn't exist, the
.Execute line should not have been reached!


the IsLoaded function only returns those objects that are loaded in the
interface. I'm not sure this applies to tables, but it may ... however,
you'd be better off doing this:

Dim tdf As DAO.Table
Dim dbs As DAO.Database

On Error Resume Next

Set dbs = CurrentDB
Set tdf = dbs.TableDefs("TableName")

If Err.number =0 Then
'/no error, so remove the table
<your delete code here>
Else

End If
 
Good idea, Scott. Thanks!

Scott McDaniel said:
Allen_N said:
I use the following code to check for the existence of a table, and drop it
if True:

Application.RefreshDatabaseWindow

For Each obj In dbs.AllTables
If obj.Name = strTable Then
If obj.IsLoaded = True Then
DoCmd.Close acTable, strTable, acSaveNo
End If
CurrentProject.Connection.Execute _
"DROP TABLE " & strTable
DoEvents
Exit For
End If
Next obj

Why should this be giving me the message, "Cannot drop the table [name],
because it does not exist in the system catalog"? If it didn't exist, the
.Execute line should not have been reached!


the IsLoaded function only returns those objects that are loaded in the
interface. I'm not sure this applies to tables, but it may ... however,
you'd be better off doing this:

Dim tdf As DAO.Table
Dim dbs As DAO.Database

On Error Resume Next

Set dbs = CurrentDB
Set tdf = dbs.TableDefs("TableName")

If Err.number =0 Then
'/no error, so remove the table
<your delete code here>
Else

End If
 
Back
Top