Good afternoon,
I have a form that adds data to a table and after user clicks on the cmdOK
button, a msgbox appears that asks them a yes/no question.
After a while, I expect the user to get tired of this question, and will
want it to go away.
Is there anyway I can programmatically allow the user to disable a message
box?
Why a yes/no question when the only thing you are doing with the
MsgBox is displaying information?
Here is a very simple and quick method, but not using the built-in
MsgBox.
Just create your own form to be used as a message form.
Add a label with whatever text you wish to display.
Add a Command button with code to close this form.
DoCmd.Close acForm, Me.Name
Add a check box to this form.
Code the Check Box AfterUpdate event:
CurrentDb.Execute "Update tblHideMessage Set tblHideMessage.[HideOK] =
" & Me.[CheckBoxName], dbFailOnError
As the label caption for this check box write:
"Do not show this message again."
Code the form's Open event:
If DSum("[HideOK]","tblHideMessage") = -1 then
Cancel = true
End If
Name this form "frmMessage".
Add a table with just one field to your database.
Table name "tblHideMessage"
Field Name "HideOK" Yes/no datatype
Set the field's value to No (0).
Code the cmdOK command button that you are using to display this
message instead of the MsgBox:
On Error GoTo Err_Handler
DoCmd.OpenForm "frmMessage", , , , , acDialog
Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error: " & "Err.Number & " " & err.description
End If
Resume Exit_Sub
When the code runs to display the message, if the Check box has not
been checked the form will open and wait for the user to click on it's
command button before any further processing is done.
If the [HideOK] field has been checked, the form will not open.
Any time you wish to start re-showing the message form, simply change
the value of the [HideOK] field (manually or by code) back to 0.
Alternatively, you can look at how Microsoft hides a form by examining
the Startup form and it's code in the Northwind sample database that
ships with Access.