Solved

Custom Error Messages

Posted on 2002-07-19
5
216 Views
Last Modified: 2011-10-03
How do I create customized error message boxes?
0
Comment
Question by:sundarag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

630 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