Results 1 to 9 of 9
  1. #1
    Mattbro is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    100

    Form closing down on afterupdate


    Hi All,
    I have a form "FormKC"with a textbox "BoxNo". The user scans a barcode and the text and the afterupdate code runs a query in which the user name and scanned data is appended by the query to a table. The text is then set to " " (erased) and the process designed to continue...but every time I go to repeat the process, upon scanning, the form closes down. Can't see why. I have attached the code (has warning suppressors)
    Code:
    Private Sub BoxNo_AfterUpdate()
    On Error GoTo ErrorHandler
    DoCmd.SetWarnings False
      DoCmd.Hourglass True
    DoCmd.OpenQuery "QryAllocateKC"
    BoxNo.Value = ""
    Me.Refresh
    Exit_Handler:
      DoCmd.SetWarnings True
    DoCmd.Hourglass False
    Exit Sub
    ErrorHandler:
    Select Case Err
    Case 2051
    'do nothing
    Case Else
    MsgBox "An error was encountered" & vbCrLf & vbCrLf & _
    "Description: " & Err.Description & vbCrLf & _
    "Error Number: " & Err.Number, , "Error"
    End Select
    End Sub
    Can anyone see what would make the form close?
    Many thanks,
    M

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Nothing should close the form.
    but why do you run ME.requery?
    if you set the text box, there's no need to refresh the form.
    but you could comment out items to see which is crashing the form.

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Are you sure the cursor is back on BoxNo field to do the 2nd scan? Could be something on Scanner settings also. Put a break point on the Docmd.setwarnings top line and step through the process F8 to see what it is doing.

    Maybe do a Requery instead of Refresh or use both. Maybe set BoxNo to null instead of "".

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I agree with Bulzie about setting BoxNo to Null instead of a Zero-Length String...but as to the problem, the first thing that I'd do would be to comment out all of your error handling as well as the code turning warnings off and see what errors/messages pop up.

    Also, the lines

    DoCmd.SetWarnings True
    DoCmd.Hourglass False


    probably should be in the main body of the sub instead of in the ExitHandler...I believe an error would cause the ExitHandler to be bypassed, and Warnings would remain Off...ditto if an error is popped.

    Linq ;0)>

  5. #5
    Mattbro is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    100
    Thanks for the tips everyone. Bulzie has identified the key problem-focus is moving to the close button. Will modify BoxNo to Null-thanks for the tip. Trying to get focus to stay on the textbox in question
    Code:
    DoCmd.OpenQuery "QryAllocateKC"
    BoxNo.Value = Null
    Me.BoxNo.SetFocus
    The null is fine, but focus is still jumping to the close button. Have tried Forms!FormKC!BoxNo.SetFocus and that doesn't work either. Any ideas?
    Thanks all,
    M

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Go to all the controls on your form (except BoxNo) and in the properties, change Tab Stop to "No". Also maybe put an "End" in line after the Me.BoxNo.SetFocus

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Set Close button with Tab Stop=No

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by Mattbro View Post

    ...Trying to get focus to stay on the textbox in question...
    One of the many quirks, inherent in Access, is that when you're in the AfterUpdate event of a Control...the cursor isn't present in the Control...and you can't return it there by setting Focus on the Control!

    What you have to do is to set Focus on another Control then set Focus back to the target Control.

    So, something like this:

    Code:
    BoxNo.Value = Null
    Me.AnyOtherControlName.SetFocus
    Me.BoxNo.SetFocus

    where AnyOtherControlName is just that...the name of any other Control that can have Focus!

    Linq ;0)>

  9. #9
    Mattbro is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    100
    Hi all, many thanks for your input. The tab stop issue has solved it-thanks for your tip also, Missinglinq. M

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

Similar Threads

  1. afterupdate data disappears from form
    By slimjen in forum Forms
    Replies: 3
    Last Post: 03-22-2016, 10:29 AM
  2. Afterupdate form, Certain Fields
    By sovereign in forum Forms
    Replies: 7
    Last Post: 05-19-2015, 07:39 AM
  3. Replies: 4
    Last Post: 10-29-2014, 03:49 PM
  4. Form AfterUpdate Event
    By RayMilhon in forum Forms
    Replies: 2
    Last Post: 09-09-2011, 09:20 AM
  5. Validation Rule Form AfterUpdate
    By GraemeG in forum Programming
    Replies: 6
    Last Post: 02-09-2011, 10:22 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