Goto new record of subform and force a save using the default values ?

R

Richard

Experts:

A bound form X contains a bound subform Y and they are linked via
Child/Master settings.

UF is an unbound form that contains subform X and a command button
"New"

When new is clicked the event handler does
Me.X.Field1.DefaultValue = """New Field 1"""
Me.X.Field2.DefaultValue = """New Field 2"""
Me.X.Field3.DefaultValue = """New Field 3"""
Me.X.SetFocus
DoCmd.GoToRecord , , acNewRec

The new record is gone to, and the default values are shown as
expected. But the record does not get written to tblX.

How can I force the new record to get written to the table ?

Thanks,
 
A

Allen Browne

You could dirty the record by assigning the existing (default) value to a
control, and then saving:

With Me.X.Form
!Field1 = !Field1
.Dirty = False
End With

If you just wanted a new record added, it might be easier to AddNew to its
RecordsetClone, and then display that record:

Dim rs As DAO.Recordset
With Me.X.Form
Set rs = .RecordsetClone
rs.AddNew
rs!Field1 = "New Field 1"
rs!Field2 = "New Field 2"
'etc
rs.Update
.Bookmark = rs.LastModified
Set rs = Nothing
End With
 

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