how do I get a custom message box to open?

K

Kathy R.

I have a form/subform where I need to have the event and date entered on
the main form before information can be entered into the subform.

How do I get a custom message box to pop up instead of the generic "You
must enter a value in the ... field" when the event and date have not
been entered?


I think that the order I want to do things in is the following. Help
with the actual VBA would be very much appreciated.

- What event to use?
- check to see if AtEventID is null - do I need this step? Because both
the date and event fields are required, Access automatically pops up the
generic message box.
- if not okay, enter info
- if null then message box

Thank you!
Kathy R.
 
F

fredg

I have a form/subform where I need to have the event and date entered on
the main form before information can be entered into the subform.

How do I get a custom message box to pop up instead of the generic "You
must enter a value in the ... field" when the event and date have not
been entered?

I think that the order I want to do things in is the following. Help
with the actual VBA would be very much appreciated.

- What event to use?
- check to see if AtEventID is null - do I need this step? Because both
the date and event fields are required, Access automatically pops up the
generic message box.
- if not okay, enter info
- if null then message box

Thank you!
Kathy R.

You can use code to replace the system message with your own.

Here's how you can find the correct error and show your own message
for any of the form level errors.

First code the Form's Error event:

MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message

Then open the form and intentionally make that error.

The message box will display the error number and then the default
error
message.

Next, go back to the Form's error event and change that code to:

If DataErr = XXXX Then
Response = acDataErrContinue ' Don't display the default
message
MsgBox "Present your own message here."
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.
 
J

John W. Vinson

I have a form/subform where I need to have the event and date entered on
the main form before information can be entered into the subform.

How do I get a custom message box to pop up instead of the generic "You
must enter a value in the ... field" when the event and date have not
been entered?


I think that the order I want to do things in is the following. Help
with the actual VBA would be very much appreciated.

- What event to use?
- check to see if AtEventID is null - do I need this step? Because both
the date and event fields are required, Access automatically pops up the
generic message box.
- if not okay, enter info
- if null then message box

Thank you!
Kathy R.

I'd use the mainform's BeforeUpdate event. Access will (try to) save the
mainform record when you set focus to the subform, firing the BeforeUpdate
event. This will avoid the generic error and allow you to check it, and cancel
the update if there is data missing; e.g.

Private Sub Form_BeforeUpdate(Cancel as Integer)
If IsNull(Me!AtEventID) Then
MsgBox "You must enter something into AtEventID", vbOKOnly
(use your preferred message of course)
Cancel = True
End If
If IsNull(Me!EventDate) Then
<same drill>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top