DELETE VBA...One works and the other doesn't (1 Viewer)

BrokenBiker

ManicMechanic
Local time
Today, 04:55
Joined
Mar 22, 2006
Messages
128
well...for those of you who've been following my recent problems, thanks for the help. Things are going well...but I'm back with another question.

I was able to get the append queries working in VBA w/ the destination db as a variable. The next step in my db is a series of DELETE queries.

I got the first one to work, but the rest of them get errors stating that there's a missing operator.
Code:
'--------------Main Table Delete--------------This one works---
Dim qryDel As String

qryDel = "DELETE [Main Table].[Report Number], [Main Table].Rating, [Main Table].Pass, [Main Table].Fail, [Main Table].[Non Rated], [Main Table].[Chief Insp Review], [Main Table].[Inspection Type], [Main Table].TEC, [Main Table].Date, [Main Table].Shift, [Main Table].Time, [Main Table].[Inspector  Number], [Main Table].[Supervisor Rank], [Main Table].[Supervisor Name], [Main Table].Location, [Main Table].[Equipment Type], [Main Table].[Equipment SN], [Main Table].Workcenter, [Main Table].Description, [Main Table].[Main Assessee]" & _
"FROM [Main Table] " & _
"WHERE ((([Main Table].Date)<Now()))"

DoCmd.SetWarnings False
DoCmd.RunSQL qryDel
MsgBox "Old records from Main Table deleted.", vbExclamation, "System Notice"

'--------------Inspected Employees Delete--------------This one doesn't----
Dim qryDelInsp As String

qryDelInsp = "DELETE [Inspected Employee Table].ReportNum, [Inspected Employee Table].EmpNum, [Inspected Employee Table].Rating, [Inspected Employee Table].[Total Inspectees], [Inspected Employee Table].Workcenter, [Inspected Employee Table].Pass, [Inspected Employee Table].Fail, [Inspected Employee Table].[Non Rated], [Inspected Employee Table].date" & _
"FROM [Inspected Employee Table] " & _
"WHERE ((([Inspected Employee Table].Date)<Now()))"

DoCmd.SetWarnings False
DoCmd.RunSQL qryDelInsp
MsgBox "Old records from Inspected Employees deleted.", vbExclamation, "System Notice"

The Main Table Delete code works fine. I copied it and then changed it up for the Inspected Employee delete SQL. I copied the SQL from a working copy of a designed delete-query, but I get errors. I can't find any difference between the two sets of code.

This has left me dazed and confused.:rolleyes:
 

MarkK

bit cruncher
Local time
Today, 02:55
Joined
Mar 17, 2004
Messages
8,187
This line ...
Code:
qryDelInsp = "DELETE [Inspected ... ... Employee Table].date" & _
... may need another space at the end.
Code:
qryDelInsp = "DELETE [Inspected ... ... Employee Table].date " & _
 

RuralGuy

AWF VIP
Local time
Today, 03:55
Joined
Jul 2, 2005
Messages
13,826
If you are deleting records then why not "DELETE * FROM ..."? It is not necessary to call out every field in the record.
 

BrokenBiker

ManicMechanic
Local time
Today, 04:55
Joined
Mar 22, 2006
Messages
128
I'm still learning about putting SQL in VBA, so I tried both solutions....Both worked. Thanks.

Learning curves can be steep...:rolleyes:
 

RuralGuy

AWF VIP
Local time
Today, 03:55
Joined
Jul 2, 2005
Messages
13,826
But that is where the fun is! Thanks for posting back with your success.
 

Users who are viewing this thread

Top Bottom