Check of Dirty Subform NOT working

G

Guest

I have learn so much from these newsgroups so thanks in advance.

I have a Form with a subform.

I have navigation buttons which check if the Main Form is dirty before
moving on

I have tried to do the same for the subform but it does not work.

Here is the code from the Next button

Private Sub cmdNext_SORMARec_Click()
On Error GoTo Err_cmdNext_SORMARec_Click

'Check for changes before Moving On & Prompt User
'Check if it has been updated
If lblUpdated.Caption = "Updated" Then
DoCmd.GoToRecord , , acNext
lblUpdated.Caption = " "
End If
'If not updated then check for bad entries
If Me.Dirty Then
' Prompt to confirm the save operation.
If MsgBox("Data has changed " & vbCrLf & "Do you want to save ? ",
vbYesNo + vbQuestion, _
"Data Changed") = vbNo Then
Me.Undo
End If
'Check for dirty subform - Not Working!
If Me.RS_Results_subform.Form.Dirty Then
' Prompt to confirm the save operation.
If MsgBox("Data has changed " & vbCrLf & "Do you want to save ? ",
vbYesNo + vbQuestion, _
"Data Changed") = vbNo Then
Me.Undo
End If
End If
End If
DoCmd.GoToRecord , , acNext

Exit_cmdNext_SORMARec_Click:
Exit Sub

Err_cmdNext_SORMARec_Click:
MsgBox Err.Description
Resume Exit_cmdNext_SORMARec_Click

End Sub

The first two work OK, but the second "If Me.RS_Results_subform.Form.Dirty
Then" just gets ignored.

I have tried using "If
Forms!sorma_records_Edit.RS_Results_subform.Form.Dirty Then" but this is also
ignored

so changes to the subform are saved without being questioned.

Any Ideas where I'm going wrong?

I will nest the if thens when happy it's working.
--
Cheers
Chas

***************
* Spectrum is Green *
***************
 
D

Douglas J Steele

I believe your subform has already written to the table, since you've moved
focus away from it.
 
R

Rick Brandt

Chas said:
I have learn so much from these newsgroups so thanks in advance.

I have a Form with a subform.

I have navigation buttons which check if the Main Form is dirty before
moving on

I have tried to do the same for the subform but it does not work.

Here is the code from the Next button
[snip]

If you're button is on the main form then the subform will never be dirty.
Moving focus from the subform to the main form causes any changes in the subform
to be saved automatically.
 
G

Guest

Dear Rick and Douglas,

Thanks for the explaination. I have to say Ricks was much clearer! ;-)

Rick, Yes there are navigation buttons on both forms and the me.dirty works
OK on both individually but I wanted a check for BOTh on the nav buttons on
the main form.
Is there anyway to check the dirty subform when moving to the nav button on
the main form? I tried a me.dirty on the after update event of the subform
but it did not work. Should I try this on the after update of each control on
the sub form? Is there an easy way of doing this for all controls? I have
seen something like

IF form!control ... then

but don't know the syntax or how to iterate all the controls (10) on the form.
--
Cheers
Chas

***************
* Spectrum is Green *
***************
 
D

Douglas J Steele

As Rick explained, no, it's not possible.

As soon as you move focus away from the subform (such as will happen when
you click on a control on the main form), the subform will write to the
database, and so will not be dirty anymore.
 
G

Guest

OK Doug,
Thanks for that. It's just a shame that the event After Update of the
subform becomes useless in this case.
--
Cheers
Chas

***************
* Spectrum is Green *
***************
 
G

George Nicholson

It's just a shame that the event After Update of the
subform becomes useless in this case.

That's because AfterUpdate isn't the right event to test Dirty.

Try the BeforeUpdate of the subform. If the form has changed, Dirty will be
True before the update (i.e., before the save) and, of course, False after
the update.

HTH,
 

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