Solved

Custom Error Messages

Posted on 2002-07-19
5
212 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

749 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