Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to runSQL to delete record when empty.

Status
Not open for further replies.

nmapeso

Technical User
Aug 26, 2005
28
US
I have a table "tblAgent" with following fieldname

AgentID - Autonumber
Name - text
Agent_Code - text

Need to runSQL to delete record when Name & Agen_Code are empty. I try this thiss but not sure what syntax on WHERE.

DoCmd.RunSQL "DELETE * FROM tblAgent WHRERE tblAgent.Agent_Code = ????" not sure what syntax on where.

Thanks for Anyhelp
 
The only strange "value" is NULL. If you want to delete records where tblAgent.Agent_code is null then your syntax is "DoCmd.RunSQL "DELETE * FROM tblAgent WHRERE tblAgent.Agent_Code IS NULL"

All other value's use the = sign like you have.
 
delete record when Name & Agen_Code are empty
DoCmd.RunSQL "DELETE FROM tblAgent WHERE Trim(Agent_Code & [Name] & '') = ''"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How are ya nmapeso . . . . .

First try this:
Code:
[blue]   Dim SQL As String
   
   SQL = "DELETE AgentID " & _
         "FROM tblAgent " & _
         "WHERE Name Is Null AND " & _
               "Agent_Code Is Null"
   DoCmd.RunSQL SQL[/blue]
Since an ounce of prevention is worth a pound of cure, to your knowledge, [blue]how are these orphaned records[/blue] (records with AgentID and no other data) [blue]coming about?[/blue]

[purple]You really need to correct this problem at the source . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top