Restoring Checkboxes on Form Close

G

Guest

I have a bunch of checkboxes to include certain things in a calculation by
default. Others can be added by clicking other checkboxes. What I want is
for the checkboxes (and everything else) to return to their original state
when the form is closed. I used this:

Private Sub Command559_Click()
On Error GoTo Err_Command559_Click
If Me.Dirty = True Then
Me.Undo
End If
DoCmd.Close

Exit_Command559_Click:
Exit Sub

Err_Command559_Click:
MsgBox Err.Description
Resume Exit_Command559_Click

End Sub

For and Exit Button and it works great...but if the user clicks the upper
right X to close the form, instead of the button, the "On Dirty" is ignored
and the changes are saved.

I tried this, but it doesn't work:

Private Sub Form_Close()
If Me.Dirty = True Then
Me.Undo
End If
End Sub

What am I doing wrong?
 
W

Wayne Morgan

The Close event is too late, as you've noticed. Try the UnLoad event
instead. You can also Cancel the closing of the form in the Unload event, if
you want to.

If that doesn't work, you'll need to remove the close button on the form and
just have the user use the button you've created.
 
G

Guest

Thanks...will that prevent ALL the records from updating through that
particular form?
See...the user goes through, makes his selections, then prints a report
based on those selections. When the form is closed, ALL those changes should
be removed.
 
W

Wayne Morgan

No, it will only undo the current, dirty record. The other records are no
longer dirty, they were saved as soon as you moved off of them. Why are you
needing to change data on multiple records, print the changed data, yet keep
the original data instead of the changes? To do this, you'll need a
temporary table to copy the records into, make the changes, and print from
that table. Clear the table when you're done.
 

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