Query (1 Viewer)

krieb

New member
Local time
Today, 05:05
Joined
Jan 22, 2000
Messages
9
I have created a query which queries another query. The information is then used to generate a report. All the information gets posted on the report and is working great. Here is the problem: I have also created a form which asks the user to choose a CROP (this is the criteria I would like to use for the query). I then have a command button that has the following code:
On Click
DoCmd.Openreport "reportname", acnormal,acpreview.
The report uses the query as its data source. When I select a crop on the form and hit the command button to run the report I get a runtime error message saying that it can't find input table 2. Any ideals how I can get this to work?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:05
Joined
Feb 19, 2002
Messages
43,368
Review the syntax of the OpenReport Method in help.

DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]

Therefore, you need something like:
DoCmd.OpenReport "reportname",acpreview,,"CROP_Code = " & YourForm!YourControl

If Crop is a text field, you'll need to get quotes around it:

DoCmd.OpenReport "reportname",acpreview,,"CROP_Code = " & "'" & YourForm!YourControl & "'"
 

krieb

New member
Local time
Today, 05:05
Joined
Jan 22, 2000
Messages
9
Thanks for the code, but I am a bit confused. The filtername is the name of my query? Also you have the below code:
DoCmd.OpenReport "reportname",acpreview,,"CROP_Code = " &
YourForm!YourControl

What is CROP_Code? Is this the name of the field I am using in my query?

You also stated that if Crop is a text field I will need it in quotes.

I should explain a little further. My form has a combo box which the user selects a crop. A text box is then populated with the selection. It is this text box (Text3) that I would like the query to use when running, and once run post the information on the report. I feel like I am missing something basic in the original code you sent. When I type in your code, I then get syntax message errors - I feel I am very close!!

Thanks in advance.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:05
Joined
Feb 19, 2002
Messages
43,368
The sample code does NOT specify a filter. It specifies a "wherecondition". Notice the two comas between acpreview and "Crop_code =". Crop_code is the name of the field in your table that holds CROP.
 

krieb

New member
Local time
Today, 05:05
Joined
Jan 22, 2000
Messages
9
Pat,

I finally got it to work - thanks for your help!
 

Users who are viewing this thread

Top Bottom