|
|

Right Justifying Text in a MsgBox
The standard Access message box does not allow you to right justify text, although there is confusingly a constant defined, vbMsgBoxRight, that indicates that you can!. You can try to get around this by padding with blank characters, or even create your own modal pop-up form to do this, but there is an API call, MessageBoxA, that does allow you to right justify text. Just copy and paste the code below into a module, and then you can call this in exactly the same way that you call the standard Access MsgBox function.
Option Compare Database
Option Explicit
Private Declare Function apiMessageBox Lib "user32" Alias "MessageBoxA" _
(ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Const MB_RIGHT = &H80000
Function fRMsgBox(strText As String, lngFlags As Long, Optional varCaption As Variant) As Long
On Error GoTo E_Handle
Dim lngReturn As Long
If IsMissing(varCaption) Then
varCaption = CurrentDb.Properties("AppTitle")
End If
lngReturn = apiMessageBox(Application.hWndAccessApp, strText, varCaption, lngFlags Or MB_RIGHT)
fRMsgBox = lngReturn
fExit:
On Error Resume Next
Exit Function
E_Handle:
Select Case Err.Number
Case 3270
varCaption = "Microsoft Access"
Resume Next
Case Else
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
fRMsgBox = 0
Resume fExit
End Select
End Function
|
A tip for using this function is to create your code using the standard MsgBox function, and then replace the function name with this one. That way, you can still use intelli-sense to get the constants such as vbYesNo etc.
Top
HOME |
NEW |
TABLES |
QUERIES |
FORMS |
REPORTS |
GENERAL |
API |
DOWNLOADS |
TUTORIAL |
RESOURCES
E-MAIL
Copyright & Disclaimer
|
| |