Results 1 to 3 of 3
  1. #1
    MaxQTime is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Location
    Kelowna, B.C.
    Posts
    42

    Verifying Data Before Leaving Textbox On Form


    So I've built a data entry form for a job tracking database. I've been asked to make the textbox for entering the job number give an error message if that job number already exists in the database. (before anyone says it, I'm also using autonumber for the primary key)

    I was thinking I could use the OnChange event and run a query with the VBA and then use IF ELSE to check whether that query came back null or with a match to what's in the text box. IF it matches the textbox I would use a msgbox and set focus back to that textbox.

    I'm not entirely sure how the result from the query comes back into the code, or how I should call the query. Any other help with how I'm thinking this should work would be appreciated as well.

    I'm getting there slowly.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Use DLookup or DCountdomain aggregate function in textbox BeforeUpdate event. If DCount("*", "Jobs", "JobNum='" & Me.tbxJob & "'") <> 0 Then
    Last edited by June7; 06-14-2019 at 12:45 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    MaxQTime is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Location
    Kelowna, B.C.
    Posts
    42
    Thank you for this this, it worked great.

    I wound up using "Cancel = True" to reset to the textbox instead of the setfocus.

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

Similar Threads

  1. Replies: 9
    Last Post: 09-05-2018, 11:35 AM
  2. Replies: 3
    Last Post: 10-22-2013, 02:51 PM
  3. Replies: 4
    Last Post: 06-10-2013, 08:01 AM
  4. Replies: 4
    Last Post: 12-22-2011, 03:04 AM
  5. Update new record when leaving form
    By jpkeller55 in forum Access
    Replies: 6
    Last Post: 09-08-2010, 06:35 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