MsgBox

jaydwest

JayW
Local time
Today, 05:39
Joined
Apr 22, 2003
Messages
340
MS Access 2002 Help describes inserting @'s to divide MsgBox text into sections ala MS Access Error Messages. I tried this in but it doesn't seem to work.

1) Does it work?
2) IF yes to #1, what is the syntax. I have tried

msgbox "Section1@Section2@Section3"

:confused: Thanks for your help
 
sections

Unfortunately that is for Macros only. It does work in Macros. The following line is further down the page on the help screen:

"You can't run the MsgBox action in Microsoft Visual Basic. Use the MsgBox function instead"
 
Do you know of any functions, etc... that could provide equivalent capabilities with VBA?

:cool:
 
You can thank Ricky Hicks for this trick...

Eval ("MsgBox ('Your Bold Text Here.@Your Normal Text Here.@@',0,' Your Title Here')")

That works for all versions of Access. Only Access 97 would allow a simple @ to separate and bold the first line of a message box.

HTH

[key words: bold message box]
 
msgbox function

I tested the eval("msgbox...) and it works great to replace the msgbox action, but I can't seem to get the msgbox function to work.

Can the eval function return a value so I can do this?

if eval("msg(...)") = vbno then
exit sub
end if

Thanks again. :confused:
 
msgbox function

I tested the eval("msgbox...) and it works great to replace the msgbox action, but I can't seem to get the msgbox function to work.

Can the eval function return a value so I can do this?

if eval("msg(...)") = vbno then
exit sub
end if

Thanks again. :confused:
 
This will do it...

If (Eval("MsgBox ('Your Bold Text Here.@Your Normal Text Here.@@',20,' Your Title Here')")) = vbYes Then
MsgBox "user clicked YES"
Else
MsgBox "user clicked NO"
End If

You will have to play with the aurgument numbers [20] if you need a different symbol and/or buttons.

HTH
 
Anyway to get this to work with a prompt message box? I want the text on the first line in bold:

Response = MsgBox(Prompt:="Do you want to save?" & vbNewLine & "Saving will add new Spec Number, Select 'No' to Cancel.", buttons:=vbYesNo)

Thanks!
 
1. SimoneRene, the danger of posting on a thread last active in 2003 is that a LOT of things have changed and it might be better for you to start a new thread of your very own!

2. You could also take the approach for MSGBOX that there is a third argument you can specify, which will be the title-bar text of the pop-up message box. You could put your "Do you want to save?" question in the title-bar argument.
 
Try

Code:
Eval ("MsgBox ('Do you want to save?@Saving will add new Spec Number  Select ''No'' to Cancel.@@',4)")

I couldn't find a quick solution using named arguments.
Also seems Eval has no knowledge of vb constants ---vbYesNo, vbNewLine etc
I found that 4 represents vbYesNo from this link MsgBox Constants vb
 
Code:
Public Function MsgBox2(prompt As String, Optional prompt2 As String, _
    Optional buttons As VbMsgBoxStyle, Optional title As String) As VbMsgBoxResult
    MsgBox2 = Eval("MsgBox(""" & prompt & IIf(prompt2 = "", _
        "", "@" & prompt2 & "@@") & """," & buttons & _
        IIf(title = "", ")", ",""" & title & """)"))
End Function

Code:
Response = MsgBox2(prompt:="Do you want to save?", prompt2:="Saving will add new Spec Number, Select 'No' to Cancel.", buttons:=vbYesNo)

If Response = vbYes Then
    MsgBox2 "You clicked", "Yes"
Else
    MsgBox2 "You clicked", "No"
End If
 
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:

OdRWdAAAAAElFTkSuQmCCAA==


BTW In this case, I would suggest using vbOKCancel as then you click Cancel to do just that!

Colin
 
Oops - the image got lost when I posted the above response - try again ...
C:\Users\Colin\OneDrive\Pictures\Screenshots\2017-03-29.png
 

Attachments

  • 2017-03-29.png
    2017-03-29.png
    3.8 KB · Views: 317
Thank you all for your responses I'm sure I will find a fix I can used in one of your posts! :D
 
Try

Code:
Eval ("MsgBox ('Do you want to save?@Saving will add new Spec Number  Select ''No'' to Cancel.@@',4)")

I couldn't find a quick solution using named arguments.
Also seems Eval has no knowledge of vb constants ---vbYesNo, vbNewLine etc
I found that 4 represents vbYesNo from this link MsgBox Constants vb

Worked Perfectly! Thank you jdraw :]
 
1. SimoneRene, the danger of posting on a thread last active in 2003 is that a LOT of things have changed and it might be better for you to start a new thread of your very own!

2. You could also take the approach for MSGBOX that there is a third argument you can specify, which will be the title-bar text of the pop-up message box. You could put your "Do you want to save?" question in the title-bar argument.

Thank you for the tip Doc Man, I will consider a new Thread next time :]
I will definitely look into using the Title-bar, it will look much neater!
 
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

BTW In this case, I would suggest using vbOKCancel as then you click Cancel to do just that!

Colin


Thanks for the code Colin!
I have tried it - see Image but I am getting an error..Any tips on the error code? Firstly it said FormattedMsgBox 'not defined' hence dim as string which cant be right :confused:

Thanks, Simone.
 

Attachments

  • FormattedMsgBox.png
    FormattedMsgBox.png
    33.6 KB · Views: 160

Users who are viewing this thread

Back
Top Bottom