Delete empty table (1 Viewer)

lhanes72

Registered User.
Local time
Yesterday, 18:51
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:
 

boblarson

Smeghead
Local time
Yesterday, 16:51
Joined
Jan 12, 2001
Messages
32,059
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?
 

lhanes72

Registered User.
Local time
Yesterday, 18:51
Joined
Dec 2, 2008
Messages
31
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.
 

boblarson

Smeghead
Local time
Yesterday, 16:51
Joined
Jan 12, 2001
Messages
32,059
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.
 

lhanes72

Registered User.
Local time
Yesterday, 18:51
Joined
Dec 2, 2008
Messages
31
I guess what I'm really trying to get at is, does Is Null and Is Not Null work in vba?
 

boblarson

Smeghead
Local time
Yesterday, 16:51
Joined
Jan 12, 2001
Messages
32,059
Well, in VBA you would use:

IsNull(TheItemToBeTested)
 

lhanes72

Registered User.
Local time
Yesterday, 18:51
Joined
Dec 2, 2008
Messages
31
I can't understand why vba does not recognize the fields as null when the table is empty.
 

boblarson

Smeghead
Local time
Yesterday, 16:51
Joined
Jan 12, 2001
Messages
32,059
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
 

lhanes72

Registered User.
Local time
Yesterday, 18:51
Joined
Dec 2, 2008
Messages
31
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

Top Bottom