New Record in a subform

  • Thread starter Thread starter Jess
  • Start date Start date
J

Jess

I have a main form called Mainform with a subform called Subform (container
name: SubformContainerName). I am trying to add a new record to Subform from
another form (FormX, not related to MainForm) by using the following
statement:

‘Code in FormX. FormX is not a subform of Mainform
Forms!MainForm!SubformContainerName.SetFocus
Forms!MainForm!SubformContainerName.Form!SubformField.SetFocus
RunCommand acCmdRecordsGoToNew ‘this line triggers error ‘2046’

error ‘2046’: acCmdRecordsGoToNew isn’t available now

I have also tried the below statement of code, which also triggers error
424:’ Object Required’

‘Code in FormX. FormX is not a subform of Mainform
Forms!MainForm!SubformContainerName.Form.RecordSource.AddNew ‘this line
triggers error 424

Why is Access triggering the above errors? What am I missing here?

Thanks
 
Check the .AllowAdditions property of the form.

Also, you may want to reevaluate the names of the forms to go with something
more descriptive such as 'frmOrders', 'frmMasterRecords'
 
..AllowAdditions is set to yes.

Any ideas?

David H said:
Check the .AllowAdditions property of the form.

Also, you may want to reevaluate the names of the forms to go with something
more descriptive such as 'frmOrders', 'frmMasterRecords'
 
1) Open the subform directly from the DB window. Can you add records to it
directly?

2)What exactly do you mean by 'trying to add a new record to Subform from
another form?

(Sidenote: This is one reason to choose descriptive names for your forms as
'Subform' can get confusing.)
 
Thanks for your answer. Below are the answers to your questions:

1) Open the subform directly from the DB window. Can you add records to it
directly? Yes I can

2)What exactly do you mean by 'trying to add a new record to Subform from
another form?

I have a form (main form) called Customers and another one called Orders.
Orders is a subform of Customers. I can't add new record (order) to Orders
from another form, Items. Items a form unrelated both to Orders and
Customers.

(Sidenote: This is one reason to choose descriptive names for your forms as
'Subform' can get confusing.)
 
Jess said:
Thanks for your answer. Below are the answers to your questions:

1) Open the subform directly from the DB window. Can you add records to it
directly? Yes I can

2)What exactly do you mean by 'trying to add a new record to Subform from
another form?

I have a form (main form) called Customers and another one called Orders.
Orders is a subform of Customers. I can't add new record (order) to Orders
from another form, Items. Items a form unrelated both to Orders and
Customers.

If Items is unrelated to both forms, then that is correct, you can't add
records to 'Orders'. 'Orders' would have to exist as a subform on the Items
form.

Why do you need to add an record to the 'Orders' from 'Items'?
 
Back
Top