Delete empty table

lhanes72

Registered User.
Local time
Today, 09:55
Joined
Dec 2, 2008
Messages
31
Problem: How do I delete an empty table by identifying a field in the table as null.

DoCmd.OpenTable "TableName"
If Field Is Null Then
DoCmd.Close acTable, "TableName"
DoCmd.DeleteObject acTable, "TableName"
Else
DoCmd.Close acTable, "TableName"
DoCmd.OpenForm "FormName"
End If

:confused:
 
Okay, your question just set off alarms in my head. Why is your table empty and what is its purpose for being there and why would you need code to delete it unless this is an ongoing matter?
 
The table is a temporary table created by a make-table query where the user inputs parameters. If the parameters do not exist in that query (say the user inputs "a" when they should input 1-10) the make-table is empty. If the table is empty, the macro progress is halted with its deletion.
 
I would suggest making the table ONCE and then using a delete query to empty it and then an append query to add records as needed.
 
I guess what I'm really trying to get at is, does Is Null and Is Not Null work in vba?
 
Well, in VBA you would use:

IsNull(TheItemToBeTested)
 
I can't understand why vba does not recognize the fields as null when the table is empty.
 
I can't understand why vba does not recognize the fields as null when the table is empty.

Because you aren't checking the contents of the table. You would need something like this:

Code:
If DCount("*", "TableNameHere") = 0 Then
 
That's exactly what I was trying to get it to do! I'm sorry it took that long to get around to the underlying question/problem. Thanks so much for your help. I can see this coming in handy more than this one time.
 

Users who are viewing this thread

Back
Top Bottom