Results 1 to 9 of 9
  1. #1
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171

    Error traping code for two events.

    Hello all,

    I am using this error trapping code for "Delivery Date" " beforeinsert" event and it working good.
    Code:
    Private Sub Form_BeforeInsert(Cancel As Integer)
    On Error GoTo errorline
    SERIALNO = Nz(DMax("serialno", "deliveries", "OrderID=" & Forms!Orders!ORDERID)) + 1
    exitline:
    Exit Sub
    errorline:
    Select Case Err.Number
    Case 3075
    MsgBox " Select Department & Location First"
    Cancel = True
    Case Else
    MsgBox " There was error in Program.Contact system Administrator"
    GoTo exitline
    End Select
    
    End Sub
    Now I add another event on double click to "Delivery Date"
    Code:
    Private Sub DELIVERYDATE_DblClick(Cancel As Integer)
    DELIVERYDATE.Text = Date
    So when I double click on " Delivery Date" text box then first it show me " Select department and Location First"
    and when I click "OK" then the error message come runtime error "3075"
    I add the error trapping code to both events then it is working but show me the msg two times, which not looking good.
    I want to add one error trapping code for both events.
    How I can do this?


    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
    22,652
    The code you have in the before insert event should probably be in the before update event, which is typically where validation is done. The other benefit is that event shouldn't fire when you add the date in the double click event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    I tried in "Beforeupdate" event but it is not working.
    It all working fine, but I just need to learn how to use one "Error handler" code for these two events.
    Or there is no way exept using separate for each events?
    If I use as I show in picture then it working but only show "Select Department and Location First" message twice.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    here is my database.
    after opening database try to double click on "Delivery Date" without selection "Department" and "Location".

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    As expected, if I move the before insert code to before update, the error code is not hit when double clicking on the date. How did that not work for you?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    Yes after moving the before insert code to before update, the error code not hit but the expression Dmax not working for me.
    I just want to know that can we use one error code for these two events or no?
    Bcoz this error happen when ever the order id is empty.
    and it show run time error code "3075"
    so I want to make a error handler that when ever this "run time error 3075" then that error handler apply.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The short version is no. Rather than rely on the error handler, why not test those two controls and only take action when both are filled in?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    OK thanks I will do so.

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

Similar Threads

  1. VBA code exiting no error.
    By Jmeyering in forum Programming
    Replies: 1
    Last Post: 11-12-2012, 04:29 PM
  2. Writing Code for "After Update" Table Events
    By dipique in forum Programming
    Replies: 10
    Last Post: 07-09-2012, 08:11 AM
  3. code logic error
    By mejia.j88 in forum Programming
    Replies: 17
    Last Post: 03-27-2012, 10:03 PM
  4. Error in form code
    By devesa in forum Access
    Replies: 3
    Last Post: 05-25-2010, 10:15 AM
  5. Error in Code
    By Lockrin in forum Programming
    Replies: 3
    Last Post: 02-25-2010, 03:27 PM

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