Solved

Custom Error Messages

Posted on 2002-07-19
5
209 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
ID: 7165731
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
ID: 7165771
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
ID: 7165772
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
ID: 7281520

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
ID: 7315403
This question will be placed in PAQ and points refunded.

Best regards,
ComTech
Community Support
Administrator @ EE
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

773 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