Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone please tell me how to set up a parameter query ?

Status
Not open for further replies.

Paul7905

MIS
Jun 29, 2000
205
US
I WANT TO PASS A PARAMETER TO AN EXISTING QUERY IN MY VBA CODE.


I am trying to call a crosstab query and passing it a parameter as follows :
qdf.Parameters(0) = BOTANICALSAVE$

the field BOTANICALSAVE$ Contains data that the query needs to select only records i want in the crosstab query.

I cannot get it to work ~

If I remove the statement "qdf.Parameters(0) = BOTANICALSAVE$"
and change the query to a regular cross-tab, the code runs fine (except the query returns all records and that is not what i want).

I think my problem is setting up the crosstab query correctly so that the parameter string "BOTANICALSAVE$" is processed correctly. If i run the query stand-alone and manually key in a item number when it prompts me, it returns the correct results. but will not when i try to pass it the same item number in code (i always get back 0 records when running it in code)

maybe the problem is how i am passing the parameter field ?
also, i don't see the correlation between the "parameters" and the actual criteria field in the columns in the query.
also, my access "help" file does not tell me exactly what is supposed to go into the parameter field and or how it relates to the query columns. what goes into this field ?

IN THE QUERY :

In the "criteria" field in the item-number column, in the criteria row, i have the following : [item]

in the first row of the parameters list for the query i have the following

parameter data type
[item] text


I AM USING THE FOLLOWING CODE :


Dim db As DAO.Database, qdf As QueryDef, fld As Field
Dim strSizeFldName() As String
Dim X As Integer

'store the key of the record to pass to the parameter Query
BOTANICALSAVE$ = (dblibdata.Fields(1).Value)

X = 0
Set db = CurrentDb
Set qdf = db.QueryDefs("ProdinfoReportQuery_Crosstab3")
'pass the parameter [itemnumber] to the parameter Query
qdf.Parameters(0) = BOTANICALSAVE$

X = qdf.Fields.Count

ReDim strSizeFldName(1 To X) As String

X = 0
For Each fld In qdf.Fields
X = X + 1
strSizeFldName(X) = fld.Name
Next

 
Couple of questions:
Cause you have a lot of code that does not appear (at first glance to do a whole lot)

What is your final result with the data? to change it?
To just view it?
Do you want to just print out the fields?

What is the purpose of this?
I can stream-line a lot of it for you.




DougP, MCP
dposton@universal1.com

Ask me how Bar-codes can help you be more productive.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top