Saving Records in a subform

G

Guest

Dear All:

I had searched the forum. I can't find a solution exactly what i am looking
for. Home someone can help me here.

I have a main form and subform. When I select an ID in the main form it
displays the related records in the subform. My subform's view is Datasheet
view. No other views allowed. The subform has 3 fiedls (Member,Attendence,
Remarks). What I need is I want to check whether any data is changed in the
subform, If there is a change I want to prompt for a Save. But If I say NO
to the save, I want to discard the changes made. I tried Before update of
the SUBform, but it doesn't allow me to go to next record, it keep asking me
Do you want to save the record. Here is my code.. Any help highly
appreciated.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Do you want to save the changes?"

If Me.Dirty = True Then
strMsg = MsgBox(strMsg, vbQuestion + vbYesNo, "Meeting Attendance")
If strMsg = vbNo Then
Cancel = True
Exit Sub
End If
Else
MsgBox "Your form is not dirty"
End If

End Sub
 
A

Allen Browne

If you want to undo the changes when the user says no, then immediately
after the line:
Cancel = True
add this line:
Me.Undo

BTW, you don't need to test:
If Me.Dirty = True Then
The event won't fire unless the form is dirty.
 
R

RuralGuy

Dear All:

I had searched the forum. I can't find a solution exactly what i am looking
for. Home someone can help me here.

I have a main form and subform. When I select an ID in the main form it
displays the related records in the subform. My subform's view is Datasheet
view. No other views allowed. The subform has 3 fiedls (Member,Attendence,
Remarks). What I need is I want to check whether any data is changed in the
subform, If there is a change I want to prompt for a Save. But If I say NO
to the save, I want to discard the changes made. I tried Before update of
the SUBform, but it doesn't allow me to go to next record, it keep asking me
Do you want to save the record. Here is my code.. Any help highly
appreciated.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Do you want to save the changes?"

If Me.Dirty = True Then
strMsg = MsgBox(strMsg, vbQuestion + vbYesNo, "Meeting Attendance")
If strMsg = vbNo Then
Cancel = True
Exit Sub
End If
Else
MsgBox "Your form is not dirty"
End If

End Sub

There is no need to test for Me.Dirty! The *only* time the BeforeUpdate event
fires is when Me.Dirty is true. Me.UnDo will undo *all* of the changes made on
a form so...

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Do you want to save the changes?"
If MsgBox(strMsg, vbQuestion + vbYesNo, "Meeting Attendance") = vbNo Then
Me.UnDo
End If
End Sub
_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 

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