Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nested if to check both main form and subform

Status
Not open for further replies.

beenut23

Technical User
Aug 17, 2008
8
Hello. I ave a form on which I must check if the user has changed anything on both the form and the subform. my nested if statement is wrong, I can tell, because it doesn't work at all. Before I added the two blue lines, it was fine if changes were on the form, but didn't check the subform too. I need it to check both, but don't know the correct order of events.

Code:
If Me.Dirty Then
[blue]If Me![tblNameDetails subform].Form.Dirty Then[/blue]
Select Case MsgBox("Do you want to save changes?", vbYesNoCancel)
Case vbYes
    '// If yes then, Save record and then close
    Forms![frmAddNewCase]![subfrmCaseWitnesses].Form.Requery
    DoCmd.Close
    
Case vbNo
    '// If no then Undo Changes then close
    DoCmd.RunCommand acCmdUndo
    DoCmd.Close
Case Else
    '// Do nothing
End Select
Else
    '// If not dirty then just close
    DoCmd.Close
[blue]End If[/blue]
End If

many thanks for any assistance with this.
 
The trouble is that Access will save the subform once it loses focus, so it will not be dirty. You will probably notice that Undo will not change the subform. If it is essential that the subform is checked, you will need to either run the code twice or use unbound forms.
 
The form this is on is a form which holds name information in the main part of the form, and then the address, ssn, and dob is in the subform. It has to be this way for a variety of reasons. At any rate, if I am understanding you correctly, if the user changes the ssn accidentally, which is on the subform, there is no way for them to cancel out of it and leave the ssn intact??
 
Not once either form loses focus. Put a debug.print or a message box in the before update event of each form to check out the way the forms save.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top