Trouble with an IF statement

Miked13

Registered User.
Local time
Today, 15:58
Joined
Jul 17, 2017
Messages
22
Good day All,

I created an If statement in a New Record button to check if the new entry is a duplicate, if its unique then it allow the record to be saved. If the new record is a duplicate it will not add the new entry.

Unfortunately it seems to be allowing the entry. I thought i had it right, but further testing has proven me wrong.

Code:
'Find Duplicate Value
    DoCmd.OpenQuery "qryDuplicateRequest", acViewNormal, acReadOnly
        If (DCount("*", "qryDuplicateRequest") = 0) Then
            DoCmd.GoToRecord acForm, "frmRequest", acNewRec
        Else
            Beep
            MsgBox "Currently in process. Please contact Inventory Managment", vbExclamation, "Count already Requested"
            Exit Sub
        End If
    DoCmd.Close acQuery, "qryDuplicateRequest"
    Me.Refresh

So the first part of the code is to run the query to find a duplicate(works fine). The message box appears if a duplicate is found, but i am unable to figure out how to have it STOP the New Record action.

I know the answer is simple but cant get my head around what i need to enter.
 
1. you don't need to open a query to use dcount
2. your dcount does not have any criteria - so it is returning the total number rows in your query

you haven't provided enough information to provide a more detailed response - sql to your query, more of the code - perhaps its failing and you have disabled errors, in the wrong procedure, not cancelling etc
 

Users who are viewing this thread

Back
Top Bottom