Question : Update a record using a SQL qry based on multiple criteria

Hi.  I'm just starting to use SQL script in my access databases and am still having some trouble with syntax, etc, so I need some help in a few areas..  I have a qry based form called frmECNMain.  Qry is driven by a table called ECNData.  frmECNMain contains a qry based subform called subfrmRouting.  This qry is driven by a table called Routings.   The subform is basically a routing sheet where each recipient checks off whether the project is approved or not.  Routing  is working as it should be, thanks in large part to this forum, but i need to check all  routing records within a given parent record (by ECNNo) and set a flag (RoutingNoticeComplete) in ECNData to true if all routings that match my criteria are approved.  I'm trying to run this on FrmECNMain close but I'm open to suggestions on when to run the check.  The included code is where I'm at now and it's not working.  It compiles ok and I get no errors on run but it's not updating my "RoutingCompleteFlag".  Any ideas where I've gone wrong?
Code Snippet:
1:
2:
3:
4:
5:
6:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
If DCount("1", "Routings", "nz(Approve) <> 'True' AND ECNNo=" & Me!ECNNo) = 0 Then
    DoCmd.SetWarnings False
    DoCmd.RunSQL "Update ECNData Set RoutingCompleteFlag =True Where ECNNo = " & Me!ECNNo & "AND CancelRtg = False AND Name <> 'Ted'"
    DoCmd.SetWarnings True
End If

Answer : Update a record using a SQL qry based on multiple criteria

Hi,

sorry, you're right, I meant the immediate window. I have here only the German version of Access where it is "Direktfenster"... :-)

I wonder why you got a "False" as result because a DCount can only return a number? What did you enter into the immediate window?

The column "Name" in your table can conflict with reserved keywords, so you should surround it with square brackets to be sure that it makes no problems.

Your last code segment looks OK for me, if "Me!ECNNo" could befound. I recommend to use "Me.ECNNo" instead because with this you can see if the name is written correctly with Intellisense and it will give exact compile results.
Moreover you can see if you have addressed the field in the right way - if you have this code on the wrong form it would not work and with the "!" you cannot see this.

Another method for testing the count is to execute it as a query in the query editor:

SELECT Count(RoutingID) FROM Routings WHERE Nz(Approve) <> True AND ECNNo=6

This should give you the expected number of records, the same as DCount.

Cheers,

Christian
Random Solutions  
 
programming4us programming4us