Increase the font size of message box in Microsoft

2019-08-07 04:55发布

Is it possible to increase the font size of message box in Access 2013 via vba code?

From this

small

to this

enter image description here

Some users are over 40 years old. They require a bigger size of font for viewing. Thanks!

1条回答
聊天终结者
2楼-- · 2019-08-07 05:52

The font size of system error boxes is a system control and would need to be changed on all individual computers.

You could instead trap the error in VBA and display your own messages via a UserForm, which would allow you to control the message and the font.

So, instead of

If countDuplicate > 0 Then
    MsgBox _
        "A record of this Part ID already exist. No changes can be made.", _
        vbCritical, _
        "Duplicated Record"
    Me.Undo
End If

You would have the following:

If countDuplicate > 0 Then
    frm_AlreadyExists.Show
    Me.Undo
End If

Where frm_AlreadyExists is a form that you would create and would have the message you listed above.

That should get you started. As a further step, instead of having a separate UserForm for each error, you could create an error table that would contain Error ID, Error Message, Error Type, Error Title columns.

Error ID    Error Message                 Error Type    Error Title         Button Action   Button Text
1           A record ... already exist.   Critical      Duplicated Record   SubName1        Click Here
2           ... not a valid EMPLOYEE      Critical      Invalid GID         SubName2        Click Here

Then you would call the UserForm with the following:

If countDuplicate > 0 Then
    ErrorID = 1 'You'll need to declare this variable elsewhere in your code
    frm_AlreadyExists.Show
End If

And the code to initialize the UserForm (in the UserForm code module)

Private Sub UserForm_Initialize()
    Dim lErrorID        As Long
    Dim sErrorMessage   As String
    Dim sErrorType      As String
    Dim sErrorTitle     As String
    Dim sBtnText        As String

    lErrorID = errorID

''Look up the following from the Error Table
    'sErrorMessage = Result from lookup
    'sErrorType = Result from lookup
    'sErrorTitle = Result from lookup
    'sBtnText = Result from lookup

    Me.lbl_ErrorMessage = sErrorMessage
    Me.img_ErrorType.Picture = "C:/File Location/" & sErrorType & ".jpg"
    Me.Caption = sErrorTitle
    Me.btn_Action.Caption = sBtnText
End Sub

And the code for the button click

Private Sub btn_Action_Click()
    Dim sBtnAction      As String

''Look up the following from the Error Table
    'sBtnAction = Result from lookup

    Application.Run sBtnAction

End Sub

With this and some tweaking and messing with code, you can now have a custom error/message system that would allow you (or even the user) to set the font for the messages.

查看更多
登录 后发表回答