Increase the font size of message box in Microsoft Access 2013

梦想与她 提交于 2019-12-11 02:05:25

问题


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

From this

to this

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


回答1:


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.



来源:https://stackoverflow.com/questions/23892754/increase-the-font-size-of-message-box-in-microsoft-access-2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!