Save and Close Button

R

Rabastan

I am designing a database containing patient information. On the main report
screen I have a drop down to choose the patient. I also have a button that
opens a form to add a new patient if needed. My question is how do I add a
button to "Save and Close". the new patient form after the information is
added?

Rab
 
A

Allen Browne

1. Set the command button's On Click property to:
[Event Procedure]

2. Click the Build button (...) beside this property.
Access opens the code window.

3. Between the "Private Sub..." and "End Sub", enter these 2 lines:
If Me.Dirty Then Me.Dirty = False
DoCmd.Close acForm, Me.Name

Use error handling: the first line will throw an error if the record cannot
be saved for any reason (e.g. a required field is left blank.)
 
S

Steve

On your new patient form you need a Close button with the following code in
the Click event:
DoCmd.Close.

On your form where you have the drop down to choose a patient, you need a
New Patient button with the following code in the Click event:
DoCmd.OpenForm "NameOfNewPatientForm",,,,acDialog

When you click this button, your new patient form will open. After you enter
the new patient and click the Close button on that form, the new patient
form will close automatically saving the new patient and then any code after
the above line of code will execute.

Steve
 

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