custom error messages

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
Question involving customizing error messages. How can I bold some text in the error message box, and then leave a line between two sentences in the box

Thanks
Roger
 
Roger,

Public Function FMsgBox(sLine1 As String, sLine2 As String, _
sLine3 As String, Optional lButtons As VbMsgBoxStyle = vbOKOnly, _
Optional sTitle As String = vbNullString, Optional HelpFile As Variant,
_
Optional Context As Variant) As VbMsgBoxResult
'
'Description: This function creates a formatted MsgBox
' similar to that which was available in Access 97 and
' earlier versions.
'
'Inputs: sLine1: The first line of text to be displayed.
' sLine2: The second line of text to be displayed.
' sLine3: The third line of text to be displayed.
' lButtons: The buttons to be displayed (exposed
' as a vbMsgBoxStyle enum).
' Title: The (optional) MsgBox title.
' HelpFile: The (optional) help filename.
' If HelpFile is supplied, then Context
' must also be supplied.
' Context: The (optional) context or topic ID.
'
'Outputs: The standard MsgBox return value.

Dim sPrompt As String

'All three lines must exist
If Len(sLine1) > 1 And Len(sLine2) > 0 And Len(sLine3) > 0 Then
sPrompt = sLine1 & "@" & sLine2 & "@" & sLine3

If IsMissing(HelpFile) Or IsMissing(Context) Then
FMsgBox = Eval("MsgBox(""" & sPrompt & """, " _
& lButtons & ", """ & sTitle & """)")
Else
FMsgBox = Eval("MsgBox(""" & sPrompt & """, " _
& lButtons & ", """ & sTitle & """, """ _
& HelpFile & """, " & Context & ")")
End If
Else
DoCmd.Beep
MsgBox "You must supply all three lines.", _
vbOKOnly + vbExclamation, "Argument missing"
End If
End Function

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Roger said:
Hi,
Question involving customizing error messages. How can I bold some text
in the error message box, and then leave a line between two sentences in the
box?
 
I'm confused. I can put in an extra line by tabbing the text until it reaches the next line...

Is there a way to make text bold in a MsgBox function

Thanks
 
Roger,

<I can put in an extra line by tabbing the text until it reaches the next
line....>
Uhm. I have no idea what you mean by that. If you want to create extra lines
in a standard MsgBox, use the vbCrLf function:

MsgBox "This is line 1" & vbCrLf & "This is line 2" & vbCrLf & "This is line
3"

<Is there a way to make text bold in a MsgBox function?>
The only way to bold text in a MsgBox is by using the code I provided. The @
operator was used in Access 97 to format MsgBox text to provide for
srandardised message boxes. It does not work in Access 2000 or above, so you
need to encapsulate it in an Eval function.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
So if I have this as my Message in the Box, where do I apply your code to bold?

Thanks


MsgBox "The value you entered isn't valid for this field." & vbCrLf & vbCrLf & "Choose a valid name from the drop-down list or enter new observer information in the Observer Table.", _ vbInformation + vbOKOnly, _ "AMEF"
 
Roger,

fMsgBox("The value you entered isn't valid for this field.", "Choose a valid
name from the drop-down list or enter" & vbcrlf & "new observer information
in the Observer Table.", "Contact the System Administrator for more
information.", vbOKOnly+vbInformation, "Error")

And before you ask, there is NO other way to do it.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Roger said:
So if I have this as my Message in the Box, where do I apply your code to bold?

Thanks


MsgBox "The value you entered isn't valid for this field." & vbCrLf &
vbCrLf & "Choose a valid name from the drop-down list or enter new observer
information in the Observer Table.", _ vbInformation + vbOKOnly, _ "AMEF"
 
Roger,

If you don't like the idea of using fMsgBox, do as Fred suggests, and create
your own unbound form to use as a message box. That way, you can format it
any way you like.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Roger said:
So if I have this as my Message in the Box, where do I apply your code to bold?

Thanks


MsgBox "The value you entered isn't valid for this field." & vbCrLf &
vbCrLf & "Choose a valid name from the drop-down list or enter new observer
information in the Observer Table.", _ vbInformation + vbOKOnly, _ "AMEF"
 
i tried plugging it in and it didn't work. When I tinkered with it, it sometimes said there was a syntax error (probably my fault), and sometimes it said that it expects an = sign.
 
Roger,

fMsgBox is a "function", and as such, returns a value. Therefore, if you're
testing it in the Immediate Window, do it like this:

?fMsgBox("The value you entered isn't valid for this field.", "Choose a
valid
name from the drop-down list or enter" & vbcrlf & "new observer information
in the Observer Table.", "Contact the System Administrator for more
information.", vbOKOnly+vbInformation, "Error")

If you're using it in code, then do it like so:

Call fMsgBox("The value you entered isn't valid for this field.", "Choose a
valid
name from the drop-down list or enter" & vbcrlf & "new observer information
in the Observer Table.", "Contact the System Administrator for more
information.", vbOKOnly+vbInformation, "Error")

If you decide to change the text and button settings (perhaps you want an
answer to a question), then do it like this:

Dim lReturn As Long

lReturn = fMsgBox("The value you entered isn't valid for this field.",
"Choose a valid
name from the drop-down list or enter" & vbcrlf & "new observer information
in the Observer Table.", "Do you want to contact the System Administrator
for more
information.", vbYesNo+vbInformation, "Error")

If lReturn = vbYes Then
'Do whatever
Else
'Do whatever
End If

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Roger said:
i tried plugging it in and it didn't work. When I tinkered with it, it
sometimes said there was a syntax error (probably my fault), and sometimes
it said that it expects an = sign.
 
Back
Top