Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    If you respond in that way, you reduce your chances of getting assistance
    If that had been directed to me, I wouldn't be offering any further assistance. However, on the presumption you might have decided to dial things back a bit, I'll suggest the following, which is geared towards using a sub to present a message box:

    Code:
    Private Sub ForWhateverThisIs
    
    Dim strMsg As String
    After declaring all variables (Dim this or that As whatever) put
    
    On Error GoTo errHandler (call your line label what you like; I call it errHandler)
    
    your code goes here
    
    exitHere: a line label that may or may not be needed to direct flow to an exit point
    - close any recordsets
    - destroy any created objects to reclaim memory resources
    Exit Sub (without this, code will enter the error handling block)
    
    trapping the potential errors would require If statements/blocks or Select Case blocks to decide what to do. 
    For example, "Invalid use of Null" [error 94]) follows. The example also calls a sub to produce the message box, 
    which as previously stated, is optional. The message can be constructed anywhere any number of times.
    errHandler:
    
    Select Case Err.Number
     Case n
       strMsg = "Whatever #1"
       errMessage strMsg (pass the message string to ErrMessage sub)
     
     Case x
       strMsg = "Whatever #2"
       errMessage strMsg
    
     Case 94
       strMsg = "The required controls cannot be blank"
       errMessage strMsg
    
    End Select
    
    Resume exitHere 
    if code should end (the case statements might Resume or Resume Next instead, if appropriate)
    End Sub
    Code:
    Public Sub ErrMessage (str As String)
     Msgbox str (+ any options you want to add to the message box)
    End Sub
    It would also be possible to a) pass multiple parameters to the sub, such as button options; b) make it a Function so that it could return the button clicked, such as Yes or No or Cancel.
    One of the main points already made is that if your vbe options are to break on all errors, then you will expose users to the code unless the db is compiled (saved as accde). Also, when you have the editor open, you can expect code to appear regardless, but if not, and the option isn't Break on All Errors, then the code shouldn't be exposed to the users. If you have such concerns, be diligent about making backup copies.

  2. #17
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by ridders52 View Post
    Do you really think that I would have spent over 2 months doing something if a ready made solution was available?

    And a word of advice, following on from your comment in post 11


    Questions like that are done to help us help you - not because we are nosy
    If you respond in that way, you reduce your chances of getting assistance
    Sorry, that was inappropriate of me.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error Messages On Subforms, Access 2016
    By roxdrob in forum Forms
    Replies: 19
    Last Post: 10-07-2017, 11:40 PM
  2. Error messages
    By Lou_Reed in forum Access
    Replies: 8
    Last Post: 12-08-2016, 11:34 PM
  3. How to handle error messages?
    By yes sir in forum Access
    Replies: 3
    Last Post: 10-15-2011, 11:22 AM
  4. Custom messages to Access' default error messages.
    By evander in forum Programming
    Replies: 1
    Last Post: 06-26-2010, 02:06 AM
  5. Error Messages
    By DataGeek in forum Access
    Replies: 0
    Last Post: 12-06-2007, 09:56 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