Message Box

J

John

Hi
On my form "frmExitDate" I have a field called "ExitDate" and a command
button called "cmdCloseExitForm" The Field "frmExitDate" needs to be
completed if a student has left the college.

When the button "cmdCloseExitForm" is clicked I would like a Message Box to
give details about the empty field. i.e. "The Field Exit Date must be
completed".

However if the Data entry person has opened this form by accident and the
student has not left the College, I obviously need to be able to close the
form without completing the field.

Any Help Please

Regards

John
 
R

Rick Brandt

John said:
Hi
On my form "frmExitDate" I have a field called "ExitDate" and a
command button called "cmdCloseExitForm" The Field "frmExitDate"
needs to be completed if a student has left the college.

When the button "cmdCloseExitForm" is clicked I would like a Message
Box to give details about the empty field. i.e. "The Field Exit
Date must be completed".

However if the Data entry person has opened this form by accident and
the student has not left the College, I obviously need to be able to
close the form without completing the field.

Use the BeforeUpdate event of the form. That will only complain about the field
being blank if the record has been modified. If a user just opens the form and
closes it without changing anything then the event will not fire. Code would be
like...

If IsNull(Me.frmExitDate) Then
MsgBox "The Field Exit Date must be completed"
Cancel = True
End If
 
J

John

Rick,
Thanks for the reply.

The code works great untill I click OK.
The original code behind the Command Button on click event "DoCmd.Close"
still closes the form losing any data entered.
How can I prevent this from happening?

Regards

John
 
F

fredg

Rick,
Thanks for the reply.

The code works great untill I click OK.
The original code behind the Command Button on click event "DoCmd.Close"
still closes the form losing any data entered.
How can I prevent this from happening?

Regards

John

Place the code in the Form's Unload event. You can cancel the form
close there.

If IsNull([SomeControl]) or [SomeControl] = "" Then
If MsgBox ("No entry in the Blah Blah control. Close the form
anyway?",vbYesNo) = vbNo Then
Cancel = True
End If
End If
 
R

Rick Brandt

John said:
Rick,
Thanks for the reply.

The code works great untill I click OK.
The original code behind the Command Button on click event "DoCmd.Close" still
closes the form losing any data entered.
How can I prevent this from happening?

Add an explicit save to your button's code.

Me.Dirty = False
 

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