Results 1 to 12 of 12
  1. #1
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170

    Invite to Debug vs. Error Message

    Hello,



    I have a rule embedded in one of my fields that does not allow the user to enter duplicate values. I have a lot of VBA code running behind that, and when a user accidentally enters in duplicate information into that field, Access produces a VBA error and invites him/her to Debug it.

    Is there a way to replace this invitation with an error message of my creating? Barring that, what are my options here, in terms of getting rid of that message?

    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,640
    Add error trapping to the procedure:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Perfect. Thread solved. Thank you.

  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,640
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Hello,

    I tried to re-integrate this back into my DB but for some reason it is not functioniong again.

    What have I done wrong?

    Private Sub LID_AfterUpdate()
    On Error GoTo ErrorHandler
    Const cQuote = """"
    Me!Operator.DefaultValue = cQuote & Me!Operator.Value & cQuote
    Me!Process.DefaultValue = cQuote & Me!Process.Value & cQuote
    Me!Goal.DefaultValue = cQuote & Me!Goal.Value & cQuote
    ExitHandler:
    Exit Sub
    Select Case Err
    Case 3205
    MsgBox "LID has already been recorded. Please use alternative LID."
    DoCmd.Hourglass False
    Resume ExitHandler
    Case Else
    MsgBox Err.Description
    DoCmd.HourglassFalse
    Resume ExitHandler
    End Select
    DoCmd.RunCommand acCmdSaveRecord
    Me![qrySubForm subform].Requery
    Me.Requery
    If Hour(Now()) > Nz(Me.tbxHour, -1) Then
    Me.tbxCount = 0
    Me.Goal = 35
    Me.tbxHour = Hour(Now())
    End If
    Me.tbxCount = Me.tbxCount + 1
    Me.Requery
    End Sub

  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,640
    There is no line to tell it where the error handler is:

    ErrorHandler:
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Code:
    Private Sub LID_AfterUpdate()
    On Error GoTo ErrorHandler
        Const cQuote = """"
            Me!Operator.DefaultValue = cQuote & Me!Operator.Value & cQuote
            Me!Process.DefaultValue = cQuote & Me!Process.Value & cQuote
            Me!Goal.DefaultValue = cQuote & Me!Goal.Value & cQuote
    ExitHandler:
        Exit Sub
    ErrorHandler:
        Select Case Err
            Case 3205
                MsgBox "LID has already been recorded. Please use alternative LID."
                DoCmd.Hourglass False
                Resume ExitHandler
            Case Else
                MsgBox Err.Description
                DoCmd.Hourglass False
                Resume ExitHandler
            End Select
        Exit Sub
    DoCmd.RunCommand acCmdSaveRecord
    Me![qrySubForm subform].Requery
        If Hour(Now()) > Nz(Me.tbxHour, -1) Then
            Me.tbxCount = 0
            Me.Goal = 35
            Me.tbxHour = Hour(Now())
        End If
        Me.tbxCount = Me.tbxCount + 1
    Me.Requery
    End Sub
    Still does not let me save and requery the form.

  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,640
    Might help to know what "does not work" means exactly. For starters, the code starting here will never run:


    DoCmd.RunCommand acCmdSaveRecord
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Quote Originally Posted by pbaldy View Post
    Might help to know what "does not work" means exactly. For starters, the code starting here will never run:


    DoCmd.RunCommand acCmdSaveRecord
    I apologize, realized what I was doing was more than ambiguous and wanted to clarify:

    The Form will not save or requery.

    Why won't the DoCmd.RunCommand work?

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    I didn't say it wouldn't work, I said it wouldn't run.

    You have that stuff below the exit and error handlers, both of which end with "Exit Sub", which code will never progress beyond. You want all code that should run above the exit handler. Back to my link, in the area noted with:

    'Your code here
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    Gosh darn it. You are just great.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    As the joke goes, I'm a legend...in my own mind.
    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. Replies: 2
    Last Post: 06-23-2012, 11:59 PM
  2. Form debug error
    By LOUM in forum Forms
    Replies: 5
    Last Post: 06-11-2012, 11:21 AM
  3. disable debug error
    By alex_raju in forum Access
    Replies: 1
    Last Post: 08-13-2011, 12:19 PM
  4. Replies: 1
    Last Post: 01-12-2011, 10:11 AM
  5. Replies: 0
    Last Post: 10-13-2010, 03:28 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