New Record in a subform

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
 
D

David H

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'
 
J

Jess

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

David H

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

Jess

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

David H

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'?
 

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