By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Replacing the default system message box

Megalog
Expert 100+
P: 378
Hey guys-

I've implemented this replacement MsgBox (that I found through the Access Developer blog) in the current database I'm working on. It works great for error handling, or anywhere that I'm calling on a message box in VBA. Basically all you do is install a few modules, one form, and replace 'MsgBox' with the new 'Box' function wherever it's to be used.

But it's not working for native system messages, and I'm wondering if any of you know a way to get Access to default to this new message box for these types of messages as well? The only reason I ask, is this replacement message box allows to copy and paste, or save the error message as a file. It's saving the users all the hassle of writing it down or making screenshots of the errors they sometimes get. I realize this probably isnt possible, but thought I'd throw it out here to let some of you flex your mental muscles.

Thanks!

Mega
Sep 5 '08 #1
Share this Question
Share on Google+
3 Replies


missinglinq
Expert 2.5K+
P: 3,532
I'm guessing that there's not going to be an easy way of doing this! I think the only way you're going to be able to do this is to use the Form_Error event, trap every trappable error you think is likely to be generated, and write custom error messages using the addin. Being able to copy and paste the error code is a very nice feature; I can understand you wanting to use it.

Linq ;0)>
Sep 5 '08 #2

ADezii
Expert 5K+
P: 8,638
The only reason I ask, is this replacement message box allows to copy and paste, or save the error message as a file. It's saving the users all the hassle of writing it down or making screenshots of the errors they sometimes get.
Why not mimic this behavior entirely within Access?
  1. Create a Public Sub-Routine
    Expand|Select|Wrap|Line Numbers
    1. Public Sub LogErrors(dteWhen As Date, lngErrNum As Long, strDesc As String, strUser As String, _
    2.                      strSource As String, strLocation As String)
    3. Dim intNextFreeFile As Integer
    4.  
    5. intNextFreeFile = FreeFile
    6.  
    7. Open CurrentProject.Path & "\Errors.txt" For Append As #intNextFreeFile
    8.  
    9. Print #intNextFreeFile, "Error on:"; Tab(20); dteWhen
    10. Print #intNextFreeFile, "Error Number:"; Tab(19); lngErrNum
    11. Print #intNextFreeFile, "Error Description:"; Tab(20); strDesc
    12. Print #intNextFreeFile, "Source of Error:"; Tab(20); strSource
    13. Print #intNextFreeFile, "Location of Error:"; Tab(20); strLocation
    14. Print #intNextFreeFile, "Current User:"; Tab(20); strUser
    15. Print #intNextFreeFile, "*************************************************************************"
    16.  
    17. Close #intNextFreeFile
    18. End Sub
  2. Place an additional, single line of code, in your Error Handlers that calls the Routine (Line Numbers 12, 11, and 12 below:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cmdTestErrorLog_Click()
    2. On Error GoTo Err_cmdTestErrorLog_Click
    3.  
    4. 'Test the Sub-Routine
    5. Err.Raise 16
    6.  
    7. Exit_cmdTestErrorLog_Click:
    8.   Exit Sub
    9.  
    10. Err_cmdTestErrorLog_Click:
    11.   MsgBox Err.Description, vbExclamation, "Error in cmdTestErrorLog_Click()"
    12.   Call LogErrors(Now(), Err.Number, Err.Description, CurrentUser(), Err.Source, "cmdTestErrorLog_Click()")
    13.     Resume Exit_cmdTestErrorLog_Click
    14. End Sub
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cmdTestAnotherError_Click()
    2. On Error GoTo Err_cmdTestAnotherError_Click
    3.  
    4. Err.Raise 37
    5.  
    6. Exit_cmdTestAnotherError_Click:
    7.     Exit Sub
    8.  
    9. Err_cmdTestAnotherError_Click:
    10.     MsgBox Err.Description
    11.     Call LogErrors(Now(), Err.Number, Err.Description, CurrentUser(), Err.Source, "cmdTestAnotherError_Click()")
    12.       Resume Exit_cmdTestAnotherError_Click
    13. End Sub
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboTestAgain_AfterUpdate()
    2. On Error GoTo Err_cboTestAgain_AfterUpdate
    3.  
    4. 'Test the Sub-Routine
    5. Err.Raise 97
    6.  
    7. Exit_cboTestAgain_AfterUpdate:
    8.   Exit Sub
    9.  
    10. Err_cboTestAgain_AfterUpdate:
    11.   MsgBox Err.Description, vbExclamation, "Error in cmdTestErrorLog_Click()"
    12.   Call LogErrors(Now(), Err.Number, Err.Description, CurrentUser(), Err.Source, "cboTestAgain_AfterUpdate()")
    13.     Resume Exit_cboTestAgain_AfterUpdate:
    14. End Sub
  3. Errors.txt in your Current Project Path will not contain a complete History of every Error generated as long as the Routine is called. It will list exactly when the Error occurred, the Error Number and Description, the exact location of the Error, the Source of the Error, and the DB User for which the Error happened.
  4. Sample OUTPUT listed below:
    Expand|Select|Wrap|Line Numbers
    1. Error on:          9/5/2008 7:43:17 PM 
    2. Error Number:      16 
    3. Error Description: Expression too complex
    4. Source of Error:   Northwind
    5. Location of Error: cmdTestErrorLog_Click()
    6. Current User:      Admin
    7. *************************************************************************
    8. Error on:          9/5/2008 7:45:45 PM 
    9. Error Number:      37 
    10. Error Description: Application-defined or object-defined error
    11. Source of Error:   Northwind
    12. Location of Error: cmdTestAnotherError_Click()
    13. Current User:      Admin
    14. *************************************************************************
    15. Error on:          9/5/2008 7:50:31 PM 
    16. Error Number:      97 
    17. Error Description: Can not call friend function on object which is not an instance of defining class
    18. Source of Error:   Northwind
    19. Location of Error: cboTestAgain_AfterUpdate()
    20. Current User:      Admin
    21. *************************************************************************
Sep 6 '08 #3

Megalog
Expert 100+
P: 378
Thanks for the replies guys, and the code too Adezii. I'm going to work that into this db today. This still doesnt trap the native messages that are occuring outside of the error handling that I already have in place, but it will help take care of the error reporting that some of the lazy users arent doing!
Sep 6 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.