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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement based on the result of a query 1

Status
Not open for further replies.

bxgti4x4

Technical User
Feb 22, 2002
167
GB
I have a query (QryPresident_Count) which returns two fields - TxtUnit and CountOfTotal. If the CountOfTotal is greater than 2 I need to run another query (QryPresident_DeleteDuplicates(W)) to remove the unwanted records from the underlying table.

I have written the code below but when I run it I receive a message "Type Mismatch".

Code:
stDocName = "QryPresident_Count"
    DoCmd.OpenQuery stDocName, acNormal, acEdit
    If "CountOfTotal" > 2 Then
    DoCmd.OpenQuery "QryPresident_DeleteDuplicates(W)", , acEdit
    DoCmd.OpenReport "RptPresident", acPreview
    DoCmd.RunCommand acCmdZoom100
    Else
    DoCmd.OpenTable "TblPresident2"
    End If

Can anyone tell me if what I am trying to do is possible and point out where I am going wrong

Best Regards
John
 
I guess the error is here:
If "CountOfTotal" > 2 Then
Take a look at the DLookUp function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV, that was the clue I needed.

Best regards
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top