Results 1 to 4 of 4
  1. #1
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107

    Error checking in AfterUpdate event

    I'm trying to create a data validation routine in my AfterUpdate event on a text box. When the user hits ENTER after keying in the data in my textbox, I test the data against the key field in my file to make sure it exists. If it does, I display a description field in another text box and continue. That works fine. If it doesn't exist in my file, I want to clear the box and have them re-enter the data. I can clear the box, but when I exit the AfterUpdate event routine, the cursor goes to the next field. I have tried using the .SetFocus method and the .GoToControl command, but neither is working. I'm guessing it needs to be in another event routine. Below is my code:



    Private Sub CustNumberTxt_AfterUpdate()
    CustNameTxt = DLookup("cus_name", "dbo_ARCUSFIL_SQL", "cus_no = '" & CustNumberTxt & "'")
    If IsNull(CustNameTxt) Then
    CustNumberTxt = ""
    CustNumberTxt.SetFocus ' and I've tried DoCmd.GoToControl "CustNumberTxt"
    Exit Sub
    End If
    Me.Requery
    Me.Refresh

    End Sub


    Please help. Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    21,716
    Validation should generally be done in the before update event (of a control or the form), so you can use:

    Cancel = True

    A form example here:

    http://www.baldyweb.com/BeforeUpdate.htm

    You could use a combo with its limit to list property set to yes and avoid the code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    Thank you. That is a good idea.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    21,716
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Form AfterUpdate Event
    By RayMilhon in forum Forms
    Replies: 2
    Last Post: 09-09-2011, 09:20 AM
  2. AfterUpdate event help
    By 10 Gauge in forum Forms
    Replies: 11
    Last Post: 09-08-2011, 10:04 AM
  3. AfterUpdate event code error?
    By agripa86 in forum Programming
    Replies: 3
    Last Post: 08-12-2011, 09:12 AM
  4. how to created afterupdate event
    By Brigitt in forum Forms
    Replies: 2
    Last Post: 02-15-2011, 03:23 AM
  5. AfterUpdate event won't refresh subform!
    By Remster in forum Forms
    Replies: 16
    Last Post: 11-26-2010, 10:06 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 - Senior Forums