Reputation: 1396
I'm trying to figure out how to get the value from a textbox in my form (shown below) to use in a query.
So for example, how would I get the highlighted "5" to use in a query to insert it into a table, and make sure the query knows which form and which textbox to get the information from?
Then figuring out how to have the query know to look in this form and the right textbox is the part giving me trouble.
I thought it would be something like
INSERT INTO Table1 VALUES (25, PMRT_Training_ID.value, 'something');
but that just pops up a box asking for another value.
Upvotes: 1
Views: 3024
Reputation: 21370
A dynamic parameterized query object pulls value from form like:
INSERT INTO Table1 (field1, field2, field3) VALUES (25, Forms!formname.PMRT_Training_ID, 'something');
Upvotes: 1
Reputation: 16015
Assuming that your form remains open when the action query is executed, then the general syntax for referencing a value held by a control on a form is:
Forms!YourFormName!YourControlName
In the case of a subform, consider that the subform is just another control on the parent form, and so the chain of references becomes:
Forms!YourFormName!SubFormName.Form!SubFormControlName
You can test the value obtained by simply creating a new query in Access with the SQL code:
select Forms!YourFormName!YourControlName as FormValue
When run, this will yield a single record displaying whichever value was held by the control YourControlName
on the open form YourFormName
at the time of execution.
Upvotes: 2