Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post
    I'm trying to use DLookUp to see if a name exists in a database. I'm using the following code:

    If Me.LastName = DLookup("LastName", "tblStudentNames") Then
    MsgBox "This name already exists in the database."
    End If

    It seems to only be looking at the first row in the database and not the other rows. I'm not sure what I'm doing wrong or if I'm doing this correctly.

    Thanks,
    Leesha

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You must specify the third argument (the condition), otherwise DLookup will return the first name it finds.
    Try

    If Not IsNull(DLookup("LastName", "tblStudentNames", "LastName=" & Chr(34) & Me.LastName & Chr(34))) Then

    or

    If DCount("*", "tblStudentNames", "LastName=" & Chr(34) & Me.LastName & Chr(34)) > 0 Then

  3. #3
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post
    Perfect! I even tried it using a query instead of a table and it worked!

    Thanks,
    Leesha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •