Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Custom Error Messages

Posted on 2002-07-19
5
Medium Priority
?
220 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

722 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