This amounts to much the the same thing but I find it easier to use.
Add the below function FormattedMsgBox containing Eval code to a module
'NOTE: Code from
http://www.trigeminal.com/usenet/usenet015.asp
========================================================
Public Function FormattedMsgBox(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, _
Optional Title As String = vbNullString, Optional HelpFile As Variant, Optional Context As Variant) As VbMsgBoxResult
On Error GoTo Err_Handler
If IsMissing(HelpFile) Or IsMissing(Context) Then
FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
""", " & Buttons & ", """ & Title & """)")
Else
FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
""", " & Buttons & ", """ & Title & """, """ & _
HelpFile & """, " & Context & ")")
End If
Exit_Handler:
Exit Function
Err_Handler:
strProc = "FormattedMsgBox"
MsgBox "Error " & Err.Number & " in " & strProc & " procedure : " & vbNewLine & " - " & Err.Description
Resume Exit_Handler
End Function
========================================================
Now you can use this function anywhere in your database
- for example using your example as follows:
If FormattedMsgBox("Do you want to save?" & _
"@Saving will add new Spec Number " & vbNewLine & _
"Select 'No' to Cancel. @", vbYesNo,"Save this record?") = vbYes Then
'User clicked Yes - Save code goes here
Else
'User clicked No - exit sub?
End If
The formatted message box this creates is shown below:
BTW In this case, I would suggest using vbOKCancel as then you click Cancel to do just that!
Colin