How to pass a textbox value into a query?

cheer

Registered User.
Local time
Today, 23:20
Joined
Oct 30, 2009
Messages
222
Form Name: frmTest with textboxA
Query Name: qryTest with field : fldA, fldB, fldC

My current VBA coding as below :-
A) For FORM
Private Sub cmdA_Click()
DoCmd.OpenQuery "qryTest"
End Sub

B) For Query
fldA with criteria written as : textboxA

I believe the root cause of the problem come from (B). I have tried VBA code in query with criteria written as [frmTest]![textboxA] for fldA, but it still doesn't work.

How to pass the texboxA value to fldA so that query ONLY display the relevant data base on the textboxA value ?

Anyone solution out there?
 
Last edited:
Use the following;
Code:
[Forms]![frmTest]![textboxA]

Thanks. It works.

Now I have new form, name as : frmMainForm. frmTest become subform in the frmMainForm. What will be new VBA code in the query above ?

I've tried [Forms]![frmMainForm]![frmTest]![textboxA] , but it doesn't work. Error message: "Method 'Item' of object 'Forms' failed"

Any suggestion ?
 
Last edited:
Take a look here.

So it should be something like:

[Forms]![frmMainForm]![frmTest].[Form]![textboxA]

hth
Chris
 
Take a look here.

So it should be something like:

[Forms]![frmMainForm]![frmTest].[Form]![textboxA]

hth
Chris

Have tried before. Error message: "Method 'Item' of object 'Forms' failed"
 
Open the query
In the criterion where you want to refer to your textbox right click and pick Build
Navigate via the open forms to the textbox, and click on the paste-button
 
Open the query
In the criterion where you want to refer to your textbox right click and pick Build
Navigate via the open forms to the textbox, and click on the paste-button

Through the Expression Builder, the most we can achieve to generate the code is up to the SubForm and NOT the textboxA inside the SubForm.
 
Did you make the necessary changes to the code presented by stopher at post #4?

Code:
[Forms]![[COLOR="Red"]YourMainFormName[/COLOR]]![[COLOR="Red"]YourSubFormName[/COLOR]].[Form]![textboxA]
You will need to change the red sections to match the reality of your forms
 
Also be aware that you need the name of the subform holder. This is what is selected when you first click on the subform whilst the form set is in design view and may be different to the name of the SubForm itself.
 
Re #7

6a00d8341d3df553ef0133f4f7afe4970b-800wi
 

Users who are viewing this thread

Back
Top Bottom