Update Query working in second Click

Drunkenneo

Registered User.
Local time
Tomorrow, 03:47
Joined
Jun 4, 2013
Messages
192
I have written a code in VBA

DoCmd.Save
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE Nz(table.tktNo," & Chr(34) & "" & Chr(34) & "), Nz(table.flightNo," & Chr(34) & "" & Chr(34) & "), Nz(table.dateofTravel," & Chr(34) & "" & Chr(34) & "), Nz(table.dest," & Chr(34) & "" & Chr(34) & "), Nz(table.origin," & Chr(34) & "" & Chr(34) & ") FROM table WHERE (((table.tktNo) Is Null) OR ((table.flightNo) Is Null) OR ((table.dateofTravel) Is Null) OR ((table.dest) Is Null) OR ((table.origin) Is Null) AND ((table.staffName) = " & Forms!frm_Main!Cmb_Staff & " ))"
DoCmd.SetWarnings True
DoCmd.Close

When i press update after deleting some records it does not delete in forst Attempt, however it does in the second attempt. Please Help
 
If the code do what is intended to do then the this is OK.

I can only think from where come your issue.
I think that you use a subform to "delete some records". So, the focus is to that subform.
Then you click a button on the main form.

IF this is the environment then the explanation is:
First click will move the focus from the subform to the button then, the second click will activate the Click event for the button, event that run the code.

Try to use KeyDown event for the button.

Now, I think that appear as logic our requirements to show us (in words) all the environment for an issue.
 
Try using Debug.Print to actually see what is the generated SQL in the First run and the Second run and see what differs..
 
Try using Debug.Print to actually see what is the generated SQL in the First run and the Second run and see what differs..

I Tried but both times running on same query,

DELETE Nz(tblDataentry.tktNo,""), Nz(tblDataentry.flightNo,""), Nz(tblDataentry.dateofTravel,""), Nz(tblDataentry.dest,""), Nz(tblDataentry.origin,"") FROM tblDataentry WHERE (((tblDataentry.tktNo) Is Null) OR ((tblDataentry.flightNo) Is Null) OR ((tblDataentry.dateofTravel) Is Null) OR ((tblDataentry.dest) Is Null) OR ((tblDataentry.origin) Is Null) AND ((tblDataentry.staffName) = 22 ))

DELETE Nz(tblDataentry.tktNo,""), Nz(tblDataentry.flightNo,""), Nz(tblDataentry.dateofTravel,""), Nz(tblDataentry.dest,""), Nz(tblDataentry.origin,"") FROM tblDataentry WHERE (((tblDataentry.tktNo) Is Null) OR ((tblDataentry.flightNo) Is Null) OR ((tblDataentry.dateofTravel) Is Null) OR ((tblDataentry.dest) Is Null) OR ((tblDataentry.origin) Is Null) AND ((tblDataentry.staffName) = 22 ))
 
I Tried but both times running on same query,

DELETE Nz(tblDataentry.tktNo,""), Nz(tblDataentry.flightNo,""), Nz(tblDataentry.dateofTravel,""), Nz(tblDataentry.dest,""), Nz(tblDataentry.origin,"") FROM tblDataentry WHERE (((tblDataentry.tktNo) Is Null) OR ((tblDataentry.flightNo) Is Null) OR ((tblDataentry.dateofTravel) Is Null) OR ((tblDataentry.dest) Is Null) OR ((tblDataentry.origin) Is Null) AND ((tblDataentry.staffName) = 22 ))

DELETE Nz(tblDataentry.tktNo,""), Nz(tblDataentry.flightNo,""), Nz(tblDataentry.dateofTravel,""), Nz(tblDataentry.dest,""), Nz(tblDataentry.origin,"") FROM tblDataentry WHERE (((tblDataentry.tktNo) Is Null) OR ((tblDataentry.flightNo) Is Null) OR ((tblDataentry.dateofTravel) Is Null) OR ((tblDataentry.dest) Is Null) OR ((tblDataentry.origin) Is Null) AND ((tblDataentry.staffName) = 22 ))


I Found where i went wrong in the code, its solved now thanks guys..
 
Indeed,

DoCmd.RunCommand acCmdSaveRecord


CurrentDb.Execute "DELETE FROM tblDataentry WHERE (tktNo Is Null Or flightNo Is Null Or dateofTravel Is Null Or dest Is Null Or origin Is Null) And staffName=" & Forms!frm_Main!Cmb_Staff
DoCmd.Close

as DoCmd.Save does not save record, it saves the object and any changes that were made to its design such as altering property settings.
 

Users who are viewing this thread

Back
Top Bottom