DLookup Error - Wrong Number of Arguments

magster06

Registered User.
Local time
, 19:43
Joined
Sep 22, 2012
Messages
235
Hello all,

Access 2010

I am trying to check for when a user trys to enter a duplicate number.

The control that I am checking is in a subform on the main form:

Main: frmCandidateInfo
Sub: frmTestInfo

Control on the subform is: RankOrder

I am trying to check the control entry against the table entry:

Table: tblTestEvents
Field: RankOrder

Here is what I have:

Code:
Private Sub RankOrder_BeforeUpdate(Cancel As Integer)
    Dim lngRankDup As Long
    lngRankDup = Nz(DLookup("[RankOrder]", "tblTestEvents", "[RankOrder]=" & Forms!frmCandidateInfo!sfTestInfo!Form!RankOrder, 0))
    If lngRankDup <> 0 Then
        MsgBox TestEventID & " already exists in the database"
    End If
End Sub

I know that the error is due to the argument not being correct, but I am not sure how to fix it.

I have tried:
Code:
    lngRankDup = Nz(DLookup("[RankOrder]", "tblTestEvents", "[RankOrder]=" & Me.RankOrder, 0))
Code:
    lngRankDup = Nz(DLookup("[RankOrder]", "tblTestEvents", "[RankOrder]=" & [RankOrder], 0))
Code:
    lngRankDup = Nz(DLookup("[RankOrder]", "tblTestEvents", "[RankOrder]=" & Forms!sfTestInfo!Form!RankOrder, 0))

But nothing seems to work.
 
The , 0 is part of the Nz() function; you have it inside the DLookup().
 
Darn! and I have spent an hour trying to figure out why that code was not working, grrrrrrr!

Thanks a ton pbaldy!!!
 

Users who are viewing this thread

Back
Top Bottom