Help please

T

Tom

Hi all,
I created a form with a combo box and command butten that suppose to open a
report. (form1)
In addtion, i created a query. (query1)
The problem: I need that the value i choose from the combo box will be the
criteria for the query and when I will press the commnd butten, the report
will open with the results of my query. (report 1)

I hope I`m clear here.

Thanks for time and effort,
Tom
 
B

Bob Sullivan

----- Tom wrote: ----

Hi all
I created a form with a combo box and command butten that suppose to open
report. (form1
In addtion, i created a query. (query1
The problem: I need that the value i choose from the combo box will be th
criteria for the query and when I will press the commnd butten, the repor
will open with the results of my query. (report 1

I hope I`m clear here

Thanks for time and effort
To



Tom

In the criteria field of your query, include the following

Forms![Form1]![Combo1

where Combo1 is the name of the combo box field. The rest should be fine. This will use the information in the combo box as the criteria of the query. And since the command button runs the report (which is based on the query), then the information will be passed along. Just make sure the form is still open when the query runs

Bob Sulliva
 
T

Tom

Hi Bob,
Thank you for the quick answer.
I thought this is how it suppose to be and i tried it, even just to get the
results without the report and it did not work.
Any ideas why?

Thanks,
Tom
Bob Sullivan said:
----- Tom wrote: -----

Hi all,
I created a form with a combo box and command butten that suppose to open a
report. (form1)
In addtion, i created a query. (query1)
The problem: I need that the value i choose from the combo box will be the
criteria for the query and when I will press the commnd butten, the report
will open with the results of my query. (report 1)

I hope I`m clear here.

Thanks for time and effort,
Tom



Tom,

In the criteria field of your query, include the following:

Forms![Form1]![Combo1]

where Combo1 is the name of the combo box field. The rest should be fine.
This will use the information in the combo box as the criteria of the query.
And since the command button runs the report (which is based on the query),
then the information will be passed along. Just make sure the form is still
open when the query runs.
 
J

John Vinson

Hi all,
I created a form with a combo box and command butten that suppose to open a
report. (form1)
In addtion, i created a query. (query1)
The problem: I need that the value i choose from the combo box will be the
criteria for the query and when I will press the commnd butten, the report
will open with the results of my query. (report 1)

Use a criterion of

=Forms![name-of-your-from]![name-of-the-combo]

in Query1.

Base the report on Query1 (or, better, on whatever meaningful name you
choose to rename Query1) and simply use the Command Button Wizard's
open-report choice to create the button.
 
B

Baisong Wei[MSFT]

Hi Tom,

Thank you for your update. I agree with Bob and John. Here I provide you
the sample code of it, I will use the sample database in Access:
Northwind.mdb

You could create a query, 'Query1':
SELECT * FROM Employees WHERE EmployeeID=Forms!Form1!combo0;

Then you create a form 'Form'. On the form, there is a combo box named
'Combo0', its 'Row Source' is:
SELECT Employees.EmployeeID FROM Employees ORDER BY [EmployeeID];

There is also a command button named 'command2', the On Click event is as
follows:
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim stDocName As String
stDocName = "Query1"
DoCmd.OpenReport stDocName, acPreview
Exit_Command2_Click:
Exit Sub
Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click
End Sub

When choose one EmployeeID from the combo0, press the button, it will open
a report of this employeeID.

Is this the one you need? Hope this helps.

Best regards

Baisong Wei
Microsoft Online Support
 
T

Tom

Hi,
Thank you all for the help.
John, it was easy - Thank you
Tom





John Vinson said:
Hi all,
I created a form with a combo box and command butten that suppose to open a
report. (form1)
In addtion, i created a query. (query1)
The problem: I need that the value i choose from the combo box will be the
criteria for the query and when I will press the commnd butten, the report
will open with the results of my query. (report 1)

Use a criterion of

=Forms![name-of-your-from]![name-of-the-combo]

in Query1.

Base the report on Query1 (or, better, on whatever meaningful name you
choose to rename Query1) and simply use the Command Button Wizard's
open-report choice to create the button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top