Deleteing records with blank field

W

Wylie C

I have a close form command button that when I click it I want it to delete
all records in the Fishdata table where the TagNum is blank. The Delete *
From Fishdata Where TagNum = '""'; syntax does not work.
Thank you
 
W

Wylie C

I tried this and it did not work. When I comple it it shows it doesn't like
the * character. I also tried the syntax with an ; at the end and it didn't
work either. Any other ideas?
 
S

Steve Schapel

Wylie,

When you compile it? Where and how are you using this?

The syntax with the * is correct for a Delete Query. It is not
relevant whether there is a ; at the end or not.
 
W

Wylie C

Steve,
I copied your code into my code and got an error message box that read:
Compile Error..Syntax Error and the line is highlighted.
Here is the entire code for the command button:

Private Sub cmdClose_Click()
On Error GoTo Err_Command8_Click

Delete * FROM Fishdata WHERE TagNum is null
DoCmd.Close

Exit_Command8_Click:
Exit Sub

Err_Command8_Click:
MsgBox Err.Description
Resume Exit_Command8_Click

End Sub
Thanks again
 
K

Ken Snell [MVP]

PMFJI....

You must use the CurrentDb object to run the query, which should be a text
string.

Change this line:
Delete * FROM Fishdata WHERE TagNum is null

to these lines:
Dim strSQL As String
strSQL = "Delete * FROM Fishdata WHERE TagNum is null"
CurrentDb.Execute strSQL, dbFailOnError
 
S

Steve Schapel

Wylie,

No, you can't do it like that. What we have been discussing is a SQL
string. If you are trying to do something with this within an event
procedure, as you are, you have to tell VBA what to do with it. Here's
an example...

Private Sub cmdClose_Click()
On Error GoTo Err_Command8_Click

Dim strSQL As String
strSQL = "DELETE * FROM Fishdata WHERE TagNum Is Null"
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.Close acForm, Me.Name

Exit_Command8_Click:
Exit Sub

Err_Command8_Click:
MsgBox Err.Description
Resume Exit_Command8_Click

End Sub
 
W

Wylie C

Thank you. Now that I see it I understand it and will now be able to apply
the logic to other areas of the project. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top