Share via

Problem using dlookup

Anonymous
2022-02-26T17:39:03+00:00

I would like the code below to run something of it returns true and do nothing if it returns false. When I run the code I get a run time error 2471 the expression you entered as a query parameter produced this error 'Pat'. Pat is the value of the TempVar.

If Not IsNull(DLookup("FName", "dbo_Customer", "FName =" & TempVars!FirstName & "")) Then

         MsgBox "Test"

else

         Do Nothing

End If

Microsoft 365 and Office | Access | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. DBG 11,711 Reputation points Volunteer Moderator
    2022-02-26T19:15:05+00:00

    Thank you for the speedy reply.

    I will combine this with a couple of other fields to capture any duplicate inputs.

    I usually use DCount() to check for duplicates. For example:

    If DCount("*", "dbo_Customer", "FName = '" & TempVars!FirstName & "'") > 0 Then
    
        'duplicate
    
    Else
    
        'not duplicate
    
    End If
    

    Hope that helps...

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-02-26T18:11:20+00:00

    Thank you for the speedy reply.

    I will combine this with a couple of other fields to capture any duplicate inputs.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2022-02-26T17:49:35+00:00

    Try

    If Not IsNull(DLookup("FName", "dbo_Customer", "FName ='" & TempVars!FirstName & "'")) Then

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2022-02-26T17:48:46+00:00

    You're doing a textual criteria search, so you need to surround your criteria in quotes.

    DLookup("FName", "dbo_Customer", "FName = '" & TempVars!FirstName & "'")

    I also don't understand the DLookUp. Your looking up the FName by searching for the FName?

    Was this answer helpful?

    0 comments No comments