Solved Pass a textfield value to a query (1 Viewer)

yamus

Member
Local time
Today, 11:53
Joined
Aug 12, 2020
Messages
81
Hi
I am making an access app to administer computer equipement inventory
I have a form with textfield to search equipements by serial number
I also have a built access query used for this search
I used the expression builder to pass the textfield to the corespondent query field criteria
An error message appears
'Too few parameters'
Any help please
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:53
Joined
Aug 30, 2003
Messages
36,124
The error implies you're trying to use the query in a recordset or something similar? If so, the simplest solution is to wrap the form reference in the Eval() function.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:53
Joined
Oct 29, 2018
Messages
21,455
Hi. Welcome to AWF!

Also, please see if this generic function helps. Good luck!

 

yamus

Member
Local time
Today, 11:53
Joined
Aug 12, 2020
Messages
81
The error implies you're trying to use the query in a recordset or something similar? If so, the simplest solution is to wrap the form reference in the Eval() function.
The error implies you're trying to use the query in a recordset or something similar? If so, the simplest solution is to wrap the form reference in the Eval() function.
I tried this like you suggested
Eval([forms]![form1]![txtField])
I wraped the whole thing in Eval() but nothing has changed
Same error is keep occuring
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:53
Joined
Aug 30, 2003
Messages
36,124
The argument must be in quotes:

Eval("[forms]![form1]![txtField]")
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:53
Joined
Oct 29, 2018
Messages
21,455
I tried it again and now i get the "with block variable not set" error
Hi. By any chance have you looked at the link I posted earlier? Just curious...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:53
Joined
May 7, 2009
Messages
19,230
you can just add a Criteria to your Query with any name, eg:

Criteria: [p1]

now, on you form (click event of the button, etc.), set the parameter using:

DoCmd.SetParameter "p1", Me![txtField]

you can then open the query/report/form based on the Query:

DoCmd.OpenQuery "yourQueryName"
 

yamus

Member
Local time
Today, 11:53
Joined
Aug 12, 2020
Messages
81
Hi. By any chance have you looked at the link I posted earlier? Just curious...
Hi
I checked your link. It s just that i am new to access and and i am kinda in hurry to make the app. I don't inderstand generic functions
It would be very generous of you if you show me a real example
Thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:53
Joined
May 7, 2009
Messages
19,230
see this sample.
 

Attachments

  • passParameter.zip
    27.2 KB · Views: 127

yamus

Member
Local time
Today, 11:53
Joined
Aug 12, 2020
Messages
81
see this sample.
Hello
I understood the example very well but when i tried to execute the query within vba using recordset i had the 'with block variable not set error'
the reswt of your code is without change
test.PNG
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:53
Joined
May 7, 2009
Messages
19,230
you only use SetParameter on opening Queries, Reports, Forms but not recordset.
you need different approach there:

Code:
Set db = CurrentDb
Set qd = db.QueryDefs("Query1")
qd.Parameters(0) = Nz(Me.txtSearch, "ZZZZZ")
Set rs = qd.OpenRecordset(dbOpenDynaset)
Set qd = Nothing
Do Until rs.EOF
    MsgBox rs!FirstName
    rs.MoveNext
Loop
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:53
Joined
Oct 29, 2018
Messages
21,455
Hi
I checked your link. It s just that i am new to access and and i am kinda in hurry to make the app. I don't inderstand generic functions
It would be very generous of you if you show me a real example
Thanks
Hi. If you copied the generic function into your project, you can replace this:
Code:
Set rs = db.OpenRecordset("Query1", dbOpenDynaset, dbSeeChanges)
with this one:
Code:
Set rs = fDAOGenericRst("Query1", dbOpenDynaset, dbSeeChanges)
Hope that helps...
 

yamus

Member
Local time
Today, 11:53
Joined
Aug 12, 2020
Messages
81
The error implies you're trying to use the query in a recordset or something similar? If so, the simplest solution is to wrap the form reference in the Eval() function.
Now i tried what you suggested. but a message errors that says
Hi. If you copied the generic function into your project, you can replace this:
Code:
Set rs = db.OpenRecordset("Query1", dbOpenDynaset, dbSeeChanges)
with this one:
Code:
Set rs = fDAOGenericRst("Query1", dbOpenDynaset, dbSeeChanges)
Hope that helps...
Hi
I tried it and it worked fine

I appreciate your help. Thank you so much
I'd like to take your permission to post the generic function use with particular instruction for users who use access in other languages( i use french version) beacuse i encountred a problem while using the form reference. The expression builder names 'form' as 'formulaire' in french. And when using the generic function, an error occured about that access did not find the reference for 'formulaire'. So i changed it back to 'form' in the exoression builder and it worked fine
Once again, i am grateful for your help
Thank you and good luck
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:53
Joined
Oct 29, 2018
Messages
21,455
Now i tried what you suggested. but a message errors that says

Hi
I tried it and it worked fine

I appreciate your help. Thank you so much
I'd like to take your permission to post the generic function use with particular instruction for users who use access in other languages( i use french version) beacuse i encountred a problem while using the form reference. The expression builder names 'form' as 'formulaire' in french. And when using the generic function, an error occured about that access did not find the reference for 'formulaire'. So i changed it back to 'form' in the exoression builder and it worked fine
Once again, i am grateful for your help
Thank you and good luck
Hi. Glad to hear you got it sorted out. You can repost the code in French, but I would request a link back to the original source, please. Good luck with your project.

PS. Once you have posted it, you can email me a link to your post, so I can also add it to my site. Cheers!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:53
Joined
May 7, 2009
Messages
19,230
you can use the generic code provide by the moderator.
but if your parameter is not generic, say, [p1], [p2], it will cause
problem.
since you know that you use qbf on your query, so you use the
"generic" function, in which case it is not generic anymore since
you know before hand that the parameter is in the
form "Forms!formname!controlname".
 

Users who are viewing this thread

Top Bottom