How do I clear a subform when its parent displays a new record

  • Thread starter Thread starter Dan Neely
  • Start date Start date
D

Dan Neely

I have a main form frmFoo to edit records in tblFoo. One of the
fields in tblFoo is a BarID. tblBar only has a single string field to
go along with the autonumbered ID. To allow the user to easily add a
new bar at need I have a subform frmBar using tblBar as a datasource.
frmBar is set to open to the to the new record and only allows
additions not edits or deletes. A value entered into the textbox in
frmBar is only saved if the user presses enter in the textbox.

The problem I have is that whenever I click the next record in frmFoo
if there's any unsaved data in frmBar's textbox that value is saved as
well. I don't want the save to happen though in this case. Ideally
I'd prefer that the unsaved value was erased, but it being left
present but still unsaved would be acceptable.
 
if you use command buttons: (as you have to, due to access autocommit
behaviour)

Private sub cmdnext_click()
If me.dirty then
me.undo
end if
docmd.gotorecord me.name, acnext
end sub

HtH

Pieter
 
if you use command buttons: (as you have to, due to access autocommit
behaviour)

Is this event handler supposed to be tied to the next record
navigation button, or are you saying I need to write my own nav
buttons to make it work? Also, am I correct in thinking it's intended
for the main form not the child?
 
You can put code in ther Forms BeforeUpdate and/or BeforeInsert event to ask
for confirmation instead, both for main & subforms

ie

Private Sub Form_BeforeUpdate (Cancel As Integer)

Cancel= MsgBox("Save Changes?",vbOkCancel + vbQuestion) = vbCancel
If Cancel Then
Me.Undo
End If

End Sub


Pieter
 
You can put code in ther Forms BeforeUpdate and/or BeforeInsert event to ask
for confirmation instead, both for main & subforms

So there's no other way to differentiate between update being fired
because the user pressed enter in the subform, and the subform being
told to update by the main one?

If I'm reading the MS documentation on the order of events all the
subform events are designed to fire before anything on the main form
even though it's a click of the mainforms nav buttons that triggers
the entire sequence. Ugh, this looks like the most insane feature
I've ran across yet.
 
Back
Top