You could:
- set focus to the subform control;
- set focus to a control within the subform;
- move to a new record;
- write the values.
With Me.[NameOfYourSubformControlHere]
.Form.SetFocus
.Form![SomeControl].SetFocus
RunCommand acCmdRecordsGotoNew
.Form!SomeControl = SomeValue
.Form!AnotherControl = AnotherValue
'etc.
End With
Alternatively, you could add the record to the RecordsetClone of the
subform:
With Me.[NameOfYourSubformControlHere].Form.RecordsetClone
.AddNew
!SomeControl = SomeValue
!AnotherContorl = AnotherValue
'etc.
.Update
End With
Use the first approach if you want the user to be able to complete or back
out of saving the record, and the 2nd approach if you want to record saved
regardless of what the user does.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"YFS DBA" <Ny**********@prexar.com> wrote in message
news:vp************@corp.supernews.com...
How do I use VBA to insert a *new* record into a subform?
I have a master form with client information, and a sub form with billing
information. I want to click on a button ("Add Data") and have a record
inserted into the subform's table, with date created and some information
from the main table inserted into the proper fields in the subform.
After the record is inserted, the data entry operator enters a Date Of
Service and a billing code.
I've created code to copy the the information I need from the main table
and place it in the proper fields, but it always goes to the first record in
the subform and overwrites the existing data. I have to manually enter the
subform and move to a new record, then click on the "Add Data" button, it
then inserts the data on the new record line.
Thanks,
Scott