Results 1 to 5 of 5
  1. #1
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128

    Question Dlookup for Table record different than Table source on Form?

    I have two tables, "tblUsers" and "tblDailyReport". tblUsers only records Text for the field "UserNum". tblDailyReport has many fields, but has a direct relationship from UserNum to its own "UserID".



    People have the ability to add to UserNum to create their own unique user. I have a form that uses the field values from tblDailyReport. When the person fills in their User ID, there is meant to be a validation to ensure that the user was created in tblUsers before.

    Initially I used the UserID field, but I kept getting Name & Type errors. I then deleted that and created an unbound text box called "User". I tried switched to using VBA instead of an expression (which I prefer). Here is what I have as of right now:

    If DLookup("UserNum", "tblUsers", "User = '" & [Forms]![frmGenSum]![User] & "'") Then
    'Do Nothing
    Else
    MsgBox "Please input a valid User ID."
    [Forms]![frmGenSum]![User] = ""

    Exit Sub
    End If


    Nothing happens, it allows whatever characters are inserted to remain even if wrong. Am I calling the other table correctly? Is there something I have written wrong? Any help would be much appreciated. Thanks!

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Are 'UserID' and 'UserNum' - both Text fields in your tables?

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I did a quick Mock-Up of what I think your scenario is [Text data type for the UserNum & UserID fields].

    I've got this in the After Update Event for the txtUserID TextBox on my form [DailyReport]. It works the way I think you want it to.
    Code:
    Private Sub txtUserID_AfterUpdate()
    If IsNull(DLookup("UserNum", "tblUsers", "UserNum = '" & [Forms]![DailyReport]![txtUserID] & "'")) Then
      MsgBox "UserID Not Found!"
    Else
        MsgBox "UserID Found! "End If
    End Sub
    Let me know if this helps!

  4. #4
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    Thank you so much Robeen! It worked!

    BTW, I have seen your posts before and they have helped me out, so thanks for those too!

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I'm always happy when I can help here as I have received help from some of our experts & know what a blessing it has been.
    All the best!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 02-12-2012, 02:58 PM
  2. Replies: 6
    Last Post: 06-15-2011, 11:48 AM
  3. Row source from table to form
    By cameronaziz in forum Forms
    Replies: 7
    Last Post: 03-29-2011, 05:23 PM
  4. Replies: 2
    Last Post: 11-29-2010, 11:16 AM
  5. Form not displaying source table data
    By Sarge, USMC in forum Forms
    Replies: 6
    Last Post: 10-25-2010, 07:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums