DCount

brucey54

Registered User.
Local time
Today, 14:53
Joined
Jun 18, 2012
Messages
155
Hi folks, need some help with this code, I’m trying to check if a record exits, but I keep getting a error!!!


Private Sub Command10_Click()

If DCount("*", "tbl", "[ID] = "") <> 0 Then
MsgBox "This record already exists.”

Else

stDocName1 = "McrAddNewRecord"
DoCmd.RunMacro stDocName1

End If
End Sub
 
You should be comparing the ID with something from the Form
 
Hi Paul,

The ID field refers to a member of staff i.e. if the member of staff has already attended training we don’t need to add them to the database.

Basically checking the table, if staffID not found, then run macro and add a new record.
 
That is what I meant. Where is that staffID in your criteria?
Code:
Private Sub Command10_Click()
    If DCount("*", "tbl", "[ID] = [COLOR=Red][B]" & Me.StaffID[/B][/COLOR]) <> 0 Then
        MsgBox "This record already exists.”
    Else
        stDocName1 = "McrAddNewRecord"
        DoCmd.RunMacro stDocName1
    End If
End Sub
 
That is what I meant. Where is that staffID in your criteria?
Code:
Private Sub Command10_Click()
    If DCount("*", "tbl", "[ID] = [COLOR=Red][B]" & Me.StaffID[/B][/COLOR]) <> 0 Then
        MsgBox "This record already exists.”
    Else
        stDocName1 = "McrAddNewRecord"
        DoCmd.RunMacro stDocName1
    End If
End Sub

Thanks Paul, I understand now :)
 

Users who are viewing this thread

Back
Top Bottom