In Access 97 had de MsgBox-functie een gedocumenteerde syntax voor het aanmaken van geformatteerde berichtvensters door het gebruik van het @-teken. Het zou de Office-assistent gebruiken als deze aan stond. Je kon bijvoorbeeld het volgende gebruiken (uit de hulpfunctie van Access 97):
MsgBox "Verkeerde knop!@Deze knop werkt niet.@Probeer een andere.", _
vbOKOnly + vbExclamation
In Access 2000 (die VBE, de Visual Basic Editor, heeft geintegreerd), roept de VBA-MsgBox-functie Access niet aan om dit uit te voeren, zodat de formattering verloren gaat en je ook de mogelijkheid verliest om de Office-assistent te gebruiken als "front" voor je boodschappen. Maar er is een oplossing!
Als je de Eval-functie gebruikt gaat je aanroep via de Expression Servie, die samenwerkt met Access en Jet om de MsgBox-functie uit te voeren, en het zal de Access-versie aanroepen in plaats van de VBA-versie. Je kunt de volgende functie toevoegen aan je Access-database en deze functie aanroepen in plaats van de VBA-MsgBox om de 97-functionaliteit te verkrijgen:
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
If IsMissing(HelpFile) Or IsMissing(Context) Then
FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
""", " & Buttons & ", """ & Title & """)")
Else
FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
""", " & Buttons & ", """ & Title & """, """ & _
HelpFile & """, " & Context & ")")
End If
End Function
Dit is het verschil. Je mag zelf beslissen welke je beter bevalt:
|
MsgBox "Wrong button!@This button doesn't work.@Try Another.",
vbOKOnly + vbExclamation, "My Application"
|
|
FormattedMsgBox "Wrong button!@This button doesn't work.@Try Another.",
vbOKOnly + vbExclamation, "My Application"
|