Button to Add Record to subform from main form

  • Follow


How do I code a button on my main form to add a new record to a subform?

I can reference controls in the subform from the main form easily enough, 
but to add a new record uses DoCmd and that doesn't seem to work with 
subforms...

Any ideas?
0
Reply Utf 8/17/2007 2:36:01 AM

Since the code is in the subform, you will need to:
a) SetFocus to the subform control (so it becomes the active control of the 
main form), and
b) SetFocus to a control in the subform.

You can then move the subform to a new record:
    RunCommand acCmdRecordsGotoNew
Then you can start assigning values to the controls.

If you don't need the user to supply values before the record is saved, an 
alternative approach would be to AddNew to the RecordsetClone of the 
subform.

-- 
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.

"Panda" <Panda@discussions.microsoft.com> wrote in message
news:2AB5145C-7727-4680-AD41-6C9A3E089941@microsoft.com...
> How do I code a button on my main form to add a new record to a subform?
>
> I can reference controls in the subform from the main form easily enough,
> but to add a new record uses DoCmd and that doesn't seem to work with
> subforms...
>
> Any ideas? 

0
Reply Allen 8/17/2007 7:36:07 AM


1 Replies
1054 Views

(page loaded in 0.018 seconds)

Similiar Articles:
















7/30/2012 2:03:53 PM


Reply: