Undo dirty form after opening popup form


J

jgrappy

I have a subform within a main form. On the subform is an option
group with three option buttons. When you click on any of the option
buttons a popup form opens to which the user inputs a date. I need
the user to be able to click a cancel button on the popup form that
would close that form without saving changes and undo changes on the
underlying subform (i.e. return the option button to it's original
selection) that initiated the popup. Can someone help me with the
right syntax to use in the code? Thanks much!

I tried this behind the click event of the "Cancel" button on the
popup, but it didn't work:

If [frmMaster].[frmSPRINT].Dirty Then
[frmMaster].[frmSPRINT].Undo
End If
 
Ad

Advertisements

J

J_Goddard via AccessMonster.com

I assume that [frmMaster] is the main form?

Try referring to the sub-form like this:

If [frmMaster].[subformControlName].form.dirty Then
[frmMaster].[subformControlName].form.Undo
End If

where [subformControlName] is the name of the control containing the subform,
not the name of the subform itself.

John


I have a subform within a main form. On the subform is an option
group with three option buttons. When you click on any of the option
buttons a popup form opens to which the user inputs a date. I need
the user to be able to click a cancel button on the popup form that
would close that form without saving changes and undo changes on the
underlying subform (i.e. return the option button to it's original
selection) that initiated the popup. Can someone help me with the
right syntax to use in the code? Thanks much!

I tried this behind the click event of the "Cancel" button on the
popup, but it didn't work:

If [frmMaster].[frmSPRINT].Dirty Then
[frmMaster].[frmSPRINT].Undo
End If
 
J

jgrappy

Yes, frmMaster is the main form and I identified that the subform
control name is frmSPRINT......I still get the error that "Run-time
error '2465': Microsoft Office Access can't find the field '|'
referred to in your expression. Any ideas?
 
D

Dale Fye

What event are you using to popup the date input form?

I think I would use the option groups BeforeUpdate event, something like:

Private sub og_ControlName_BeforeUpdate(Cancel as integer)

Docmd.openform "frm_Popup_Date",,,,,acDialog
Cancel = (Forms("frm_Popup_Date").Tag = "Cancelled")
if not Cancel then Something = forms("frm_Popup_Date").txt_Date
docmd.close acform, "frm_Popup_Date"

End sub

This assumes that "frm_Popup_Date" has two buttons (Cancel and Close or
something like that), and that when either of these buttons is clicked, you
assign a value (Cancelled or Closed) to the forms tag property.

Then, rather than closing the form, hide it (me.visible = false). This
allows the code in your main form to continue, allowing you to check whether
the input was entered or cancelled. If "Cancelled", then setting Cancel =
True in the BeforeUpdate event will cancel the changes.

HTH
Dale
 
J

J_Goddard via AccessMonster.com

I tested the same thing you are doing, and it worked fine; here is the code
behind a command button on my test sub-form:

Private Sub Command57_Click()
If Forms![corcas - report]![module list].Form.Dirty Then
MsgBox "Sub form is dirty"
Forms![corcas - report]![module list].Form.Undo
Else
MsgBox "Sub form is NOT dirty"
End If
End Sub

The error message you are getting implies something else is wrong - since it
refers to a field and not a control. Can you post the full code behind your
command button, and indicate which line triggers the error?
 
Ad

Advertisements

J

jgrappy

John, not sure what I did wrong earlier but I used the code you
supplied in the last post and it worked perfectly. Thanks much!

-Josh
 
Ad

Advertisements


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

Similar Threads

Cancel button to undo data on subform 13
form opening 1
main form and popup 1
filling unbound form 1
Undo button 2
Popup Reports 2
"Undo changes" before saving record 1
Close popup form from a continuous subform 3

Top