Solved

Custom Error Messages

Posted on 2002-07-19
5
207 Views
Last Modified: 2011-10-03
How do I create customized error message boxes?
0
Comment
Question by:sundarag
5 Comments
 
LVL 7

Expert Comment

by:ildc
Comment Utility
What do you mean with that? Do you just want to let appear message boxes when a user does something wrong ?

If so in the vba help, you'll find a lot if you look for MSGBOX. With thi you can have your own messages, your own icons on the messages and the buttons ok, cancel, yes, no,.... as you like

Regards
0
 
LVL 28

Expert Comment

by:TextReport
Comment Utility
If you refereing to standard errors from access forms then you can use the OnError event where you can trap specific errors and return your own messages. The following is the example from help

Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Const conDuplicateKey = 3022
    Dim strMsg As String

    If DataErr = conDuplicateKey Then
        Response = acDataErrContinue
        strMsg = "Each employee record must have a unique " _
            & "employee ID number. Please recheck your data."
        MsgBox strMsg
    End If
End Sub

Within a function I normally have the following as an outline to the function / sub-routine and in the select case I can handle specific error I wish to handle, the else handles all others

Function MyFunction
On Error Goto MyFunction_Error

My code goes here

MyFunction_Exit:
    Exit Function
   
MyFunction_Error:
    Select Case Err
        Case Else
             MsgBox "An unexpected error has occoured in MyFunction." & vbCrLf & vbCrLf & Err & vbTab & Err.Description, vbCritical
             Resume MyFunction_Exit
    End Select
End Function

Cheers, Andrew
0
 
LVL 7

Expert Comment

by:Daniel Stanley
Comment Utility
this code block takes an access err number and translates and maps it to a help file, if one exists. you can modify this block to do what you want to do as far as trapping err numbers and their descriptions; based on a err number you can pop-up any msg you like.

good luck,
daniels@asix.com



CODE:
Private Sub cmdOk_Click()

    Dim strErr As String
    Dim x As String
    Dim Msg
    Dim index
   
    Err.Clear
    On Error Resume Next
   
    If IsNull(txtErrNum) Then
        MsgBox "Please enter an error number.", vbInformation, "Incomplete Data"
        Me.txtErrNum.SetFocus
    Else
        strErr = txtErrNum
        Err.Raise CInt(strErr)
        x = UCase(AccessError(strErr))
            If CStr(Err.Description) = "Application-defined or object-defined error" Then
                MsgBox "Error code not found.", vbInformation, "Help"
                Exit Sub
            Else
                MsgBox "Error " & strErr & " = " & UCase(Err.Description), vbOKOnly, "Error Code"
                If Err.Number <> 0 Then
                    If CStr(Err.Description) = "Application-defined or object-defined error" Then
                        MsgBox "No Help Available"
                        Exit Sub
                    Else
                        Msg = "Press F1 or Help to see " & Err.HelpFile & " topic for" & _
                                        " the following HelpContext: " & Err.HelpContext
                        MsgBox Msg, , "Error: " & UCase(Err.Description), Err.HelpFile, Err.HelpContext
           
                    End If
                End If
            End If
    End If

End Sub
0
 
LVL 54

Expert Comment

by:nico5038
Comment Utility

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - PAQ'd and pts removed
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 

Accepted Solution

by:
ComTech earned 0 total points
Comment Utility
This question will be placed in PAQ and points refunded.

Best regards,
ComTech
Community Support
Administrator @ EE
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now