Form/Subform Continuous form) Problem

  • Thread starter Thread starter John S
  • Start date Start date
J

John S

Back again,

I have a form (pet owners) and a subform (continuous form; pets) Both are
bound. When I try to clear the two forms for a new record entry, sometimes
the data in the subform (for pets) remains from the previous entry. This
seems to be an intermittent problem.

The code on the onclick event of a button is simply:

DoCmd.GoToRecord , , acNewRec
txtProp.SetFocus ' (the first field in the main form)

I have eliminated "txtProp.setfocus", tried requerying the subform,
refreshing the subform, and doing the doCmd.GoToRecord" command a second
time. No luck.

So how do I fix the problem?

J. Smith
Aylmer PQ
 
Access will not be able to go do a new record if the current record can't be
saved (e.g. if a required field is not filled in.) If you are
programmatically changing values in the subform, you may need to force the
subform record to save as well. If you are not changing values in the
subform, that should not be necessary (assuming that the command button is
on the main form.)

Try something like this:

Private Sub cmdGotoNew_Click()
If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
Beep
Else
RunCommand acCmdRecordsGotoNew
End If
End Sub
 
Thanks, Allen, I'm working with it now, and will let the newsgroup know how
it comes out. I've tried to use it in a button on the main form, without
success. I'll start playing with it on the sub form.

If all else fails: If it is merely a refresh type problem, I'll try clearing
by circulating through the controls (not sure if this will work on a
subform), and variants of refresh and requery.

BTW, is there any way of forcing a save on a subform? Kind of seems
illogical to try it on a subform after_update event (or before update for
that matter), but who knows. And I think the pet info is saving, the
controls are just not clearing for a new record.

Thanks again

John S.
 
Don't try forcing the save in Form_AfterUpdate or in Form_BeforeUpdate.

To force a save in a subform named "MySub" from the parent form:

With Me.[MySub].Form
If .Dirty Then
.Dirty = False
End If
End With
 
Back
Top