Close a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to add a button to a form that allows the person entering data mid-way through the form to close the form without sending the partial (incorrect) data to the table. Can someone please tell me how to do this?
 
KB,

Access inserts the record upon typing into any textbox on a bound form.
Unless you prevent this using the Form's BeforeInsert event. If the user
attempts to close before completing the record you have to delete the record
using the following command:
docmd.RunCommand acCmdDeleteRecord

You can do this in the close button procedure or the form's Unload event. I
think it's too late in the Close event.

HTH,
Josh

Kbergstrom said:
I need to add a button to a form that allows the person entering data
mid-way through the form to close the form without sending the partial
(incorrect) data to the table. Can someone please tell me how to do this?
 
Undo the form before closing.

1. Add a button to your form.

2. Set its On Click property to:
[Event Procedure]

3. Click the Build button (...) beside this, and enter this:

Private Sub cmdCancel_Click()
If Me.Dirty Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Kbergstrom said:
I need to add a button to a form that allows the person entering data
mid-way through the form to close the form without sending the partial
(incorrect) data to the table. Can someone please tell me how to do this?
 
Joshua,
Access inserts the record upon typing into any textbox on a bound form

That is oversimplified, a bound form has two sets of buffers associated with
it, the control buffers and the record buffers.
When you type into a control, the data goes into the control buffer for that
control.
When you move to another control, Access moves the data from the control
buffer to the record buffer.
When the form is moved to another record, or closed, Access moves the data
from the record buffer into the table(s) that the form is based on.

Ragnar
 
Back
Top