cancel changes on subform

K

Keith G Hicks

A2k

2 tables:
tblCustomers
tblCustomerAddresses (child of "tblCustomers")

The form frmCustomers is bound to tblCustomers. There's a subform on
frmCustomers called frmCustomerAddresses that is bound to
tblCustomerAddresses.

On frmCustomers there is an "Edit" button, a "Cancel" button and a "Save"
button. Until the "Edit" button is clicked the follwoing settings apply:

frmCustomers.AllowEdits = false
frmCustomers!frmCustomerAddresses.Form.Locked = true

When the user clicks "Edit" the above changes to the following:

frmCustomers.AllowEdits = true
frmCustomers!frmCustomerAddresses.Form.Locked = false

All of this works fine but the problem is with the "Cancel" button which is
on the frmCustomers form, not the frmCustomerAddresses form. If the user
edits data on frmCustomers and clicks "Cancel" all is good. But if he/she
edits data on frmCustomerAddresses then by the time the click occurs of
course Access has already moved off of the active record in
frmCustomerAddresses and saved it (as long as the data is valid which is
another issue). Without making the forms unbound, or without putting another
separate cancel button on the subform, how is this best handled?

Thanks,

Keith
 
G

Guest

That is a problem when using bounds forms...

One thing you can do is use the BeforeUpdate event of your subform to
present a dialog to the user asking if he/she wishes to save the records.

That way, if your user has been editing in the subform and clicks the Cancel
button on the parent form, they will be presented with the option to save or
cancel edits. Of course, if a user has been editing on the subform and clicks
on 'any' control on th parent form they will get the same message but that's
not necessarily a bad thing. It is the only opion I know of apart from making
your forms unbound.

Steve
 
G

Guest

I haven't tried this, so I don't know if it will work. Since the Cancel
button becomes active as soon as it is clicked you might be able to add
something like the following to the Before Update to limit it to only a click
of the Cancel button;

If Screen.ActiveControl.Name = "NameOfYourCancelButton" Then
 

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