Microsoft Access 2010 - I Need to Add a Row to a Table using the controls on an Active Form

I have a sub form that is linked to the main form via a query using the REQUEST_ID. I want to capture the sub form controls data and input it into a table.

My VBA is not working as I am not able to reference the sub forms controls. I want to insert into BD_TRAN where the fields in the table are set equal to the values on the form.

Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("BD_TRAN ")
With rst
     .AddNew
     '.Fields("Request_ID") = [Forms]![frmRetrieval]![REQUEST_ID].Value
     '.Fields("Source") = [Forms]![frmRetrieval]![DESTINATION]!Value
     '.Fields("RDBMS_SCHEMA") = [Forms]![frmRetrieval]![RDBMS_SCHEMA].Value
     .Update
 End With
End Sub
SharonBernalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You need to reference the subform control name:


     '.Fields("Request_ID") = [Forms]![frmRetrieval]![<subformcontrolname>].Form![REQUEST_ID].Value

  Note that you want the name of the subform control, not the name of the subform (they may not be the same).

Jim.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SharonBernalAuthor Commented:
Hello, here's the breakdown of what's represented in my code.

.Fields("Request_ID") = [Forms]![frmRetrieval]![REQUEST_ID].Value

frmRetrieval is the subform name, and REQUEST_ID is the name of the control on that form. When I run the code it comes back as null.

Now the REQUEST_ID control on frmRetrieval has as it's control source the following that references the main form

=[Forms]![BD_Request]![REQUEST_ID]
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Please refer back to Jim's comment regarding the correct way to reference Subforms.

Note also that a form that's being used as a Subform in NOT in the Access Forms collection, so you cannot refer to it through that collection. You must use the syntax that Jim suggested.
frmRetrieval is the subform name
Yes, but is it the name of the Subform CONTROL on the parent form? It may be, but that's not a guarantee - you need to open the parent form in Design view, and then check the Property settings for that Subform control to determine the name. Once you have that, use Jim's syntax to properly refer to your subform's fields.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.