Set New Record in a subform

D

David W

Hope I dont lose ya here!

I have got a main form with 2 subforms, each are linked to the mainform,
they work like they should.

What I am trying to do is to set focus to a new record in a subform.

OK,
The first subform;
I have a popup that comes from the first subform(the subform is in
continuious form mode and has a command button in each record) what that is
for is to open a form(as a popup) to view the entire contents for the record
since it cannot fit into one line.
Now, if you add or change data in the popup it does coralate with each of
its own records. Another words if you add a record, it will add a new record
to the first subform, or if you modify a record, it changes the right one.

Now,
The second subform;
It is basically a continuious form with 3 textboxes to show charges.

I can manually click in the second subform after the first subform has been
populated and enter what is needed. I would like to take a calculation from
the popup form to populate a textbox in the second subform.

What is currently happening is that if I dont click in the second subform on
a new record, before I open the popup form, the popup form will overwrite
what was previously in the textbox of the second subform.

How do you set focus to a new record in a subform?
 
A

Allen Browne

If you are trying to programmatically add a record to both subforms, without
needing any user input, the simplest thing would be to AddNew to their
RecordsetClone.

This kind of thing:

Dim rs As DAO.Recordset
If Me.NewRecord Then
MsgBox "Need main form record to create subform records."
Else
With Me.[Sub1].Form
Set rs = .RecordsetClone
rs.AddNew
!ForeignID = Me.ID
!SomeField = 99
!AnotherField = "xyz"
'etc for other fields.
rs.Update
'Make the new record the current one if desired:
Set .Boomkark = .LastModified
Set rs = Nothing
End With

With Me.[Sub2].Form
'same approach as above


If that is not suitable, you will need to:
- SetFocus to the first subform control on the main form.
- SetFocus to a control in the form in the subform control.
- RunCommand acCmdRecordsGotoNew.
- Assign the values to the text boxes in the subform.
- Explicitly save the record: RunCommand acCmdSaveRecord
- Repeat for other subform.
 

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