create report from combo box item

G

Guest

i need to generate a report after clicking the item in the combo box. e.g i
put a command button on the form for a report. when i click it, a combo box
should appear and i should select a item from it. On the base of selected
item, it should generate a report, e.g i need a report about the car based on
the model. when i click command button for report , a combo box appear with
the different model like toyota , gmc, lexus etc. and and when i click any
model , it should generate the report from the selected model...... i hope
you understand what i want. thanks
 
G

Guest

In the form where you have a button to open the report create a combo for the
user to select a value before you try to open the report, then try something
like

Dim MyCondition As String
If IsNull(Me.[ComboName]) Then
MsgBox "You need t select a model"
Else
MyCondition = "[FieldNameInTable=" & Me.[ComboName]
Docmd.OpenReport "ReportName", , , MyCondition
End If

Note: If the value passed to the report is a string use
MyCondition = "[FieldNameInTable='" & Me.[ComboName] & "'"

Adding single quote to the string
 
F

fredg

i need to generate a report after clicking the item in the combo box. e.g i
put a command button on the form for a report. when i click it, a combo box
should appear and i should select a item from it. On the base of selected
item, it should generate a report, e.g i need a report about the car based on
the model. when i click command button for report , a combo box appear with
the different model like toyota , gmc, lexus etc. and and when i click any
model , it should generate the report from the selected model...... i hope
you understand what i want. thanks

Create an unbound form.
Add a combo box.
Set the Row Source of the combo box to include the
CarID field and the Car Name.
Name the Combo Box 'FindCar'.
Set it's Bound column to 1.
Set it's Column Count property to 2.
Set the Column Width property to 0";1"

Add a Command Button to the form.
Code the button's click event:

Me.Visible = False

Name this form 'ParamForm'.

Create a query that will return all the records.
In the Query's [CarID] field criteria line write:
forms!ParamForm!FindCar

Make this query the record source for your report.

Next, code the report's Open event:
DoCmd.OpenForm "ParamForm", , , , , acDialog

Code the report's Close event:
DoCmd.Close acForm, "ParamForm"

When ready to run the report, open the report (either from the main
database folder or via code from a command button event).
The form will open and wait for the selection of the Car.
Click the command button and then report will run.
When the report closes, it will close the form.
 
G

Guest

Thanks Cohen, its really help me. but i dont want to create a combo in the
form, i only want to combo box appear when i press the command button for
report. any idea how to do this
--
Zaheer
Acesss Database Designer
Planning Supervisor


Ofer Cohen said:
In the form where you have a button to open the report create a combo for the
user to select a value before you try to open the report, then try something
like

Dim MyCondition As String
If IsNull(Me.[ComboName]) Then
MsgBox "You need t select a model"
Else
MyCondition = "[FieldNameInTable=" & Me.[ComboName]
Docmd.OpenReport "ReportName", , , MyCondition
End If

Note: If the value passed to the report is a string use
MyCondition = "[FieldNameInTable='" & Me.[ComboName] & "'"

Adding single quote to the string
--
Good Luck
BS"D


[QUOTE="Zaheer"]
i need to generate a report after clicking the item in the combo box. e.g i
put a command button on the form for a report. when i click it, a combo box
should appear and i should select a item from it. On the base of selected
item, it should generate a report, e.g i need a report about the car based on
the model. when i click command button for report , a combo box appear with
the different model like toyota , gmc, lexus etc. and and when i click any
model , it should generate the report from the selected model...... i hope
you understand what i want. thanks
[/QUOTE]
 
G

Guest

Using InputBox or Parameter query wont prompt you with a combo, it will ask
for one value that need to be inputed by the user (not selected from a list),
for that you'll need to create a form (InputBox look alike) with a combo,
when pressing the button open the new form for the user to select a value.

Create a Global variable in a module to assign the value selected to it when
the form is closed

Global MyValue as Number

On the UnLoad event of the new form write
MyValue = Nz(Me.[ComboName],0)

On the Onclick event of the button write the code that open the form, and
then using the value returned

' acDialog will stop the code until the form is closed
Docmd.OpenForm "NewFormName",,,,,acDialog
If MyValue = 0 Then
MsgBox "You need t select a model"
Else
MyCondition = "[FieldNameInTable]=" & MyValue
Docmd.OpenReport "ReportName", , , MyCondition
End If

--
Good Luck
BS"D


Zaheer said:
Thanks Cohen, its really help me. but i dont want to create a combo in the
form, i only want to combo box appear when i press the command button for
report. any idea how to do this
--
Zaheer
Acesss Database Designer
Planning Supervisor


Ofer Cohen said:
In the form where you have a button to open the report create a combo for the
user to select a value before you try to open the report, then try something
like

Dim MyCondition As String
If IsNull(Me.[ComboName]) Then
MsgBox "You need t select a model"
Else
MyCondition = "[FieldNameInTable=" & Me.[ComboName]
Docmd.OpenReport "ReportName", , , MyCondition
End If

Note: If the value passed to the report is a string use
MyCondition = "[FieldNameInTable='" & Me.[ComboName] & "'"

Adding single quote to the string
--
Good Luck
BS"D


[QUOTE="Zaheer"]
i need to generate a report after clicking the item in the combo box. e.g i
put a command button on the form for a report. when i click it, a combo box
should appear and i should select a item from it. On the base of selected
item, it should generate a report, e.g i need a report about the car based on
the model. when i click command button for report , a combo box appear with
the different model like toyota , gmc, lexus etc. and and when i click any
model , it should generate the report from the selected model...... i hope
you understand what i want. thanks
[/QUOTE]
 
G

Guest

Ofer,

This was helpful to me as well. Can't imagine why MS doesn't have a combo
or multiple, customizable buttons in InputBox/MsgBox.

I have similar situation. I have three options: "Test", "All" and "Latest"
for a report. I need to write generic script for 1000s of users to insert
into their Access databases that isn't db specific, so I must minimize
inserts to:

1. a single date-tracking table (unrelated to any existing tables).

2. a single report that pulls the relevant fields from related tables
according to user.

3. a single VB script/module thing that asks test, all, or latest then,
based on that, runs an SQL query, populates the report and automatically
TransferText's the results to a text file.

I am PHP/MySql,but have managed to code the above for FileMaker w/ a single
table, layout and script. But MS Access is turning out to not be as simple.

Is there some way to avoid creating a permanent, single-combobox Form as you
describe and generate one dynamically in the vb script and it would lit be
able to aunch on-open of the report?

oh4real

Ofer Cohen said:
Using InputBox or Parameter query wont prompt you with a combo, it will ask
for one value that need to be inputed by the user (not selected from a list),
for that you'll need to create a form (InputBox look alike) with a combo,
when pressing the button open the new form for the user to select a value.

Create a Global variable in a module to assign the value selected to it when
the form is closed

Global MyValue as Number

On the UnLoad event of the new form write
MyValue = Nz(Me.[ComboName],0)

On the Onclick event of the button write the code that open the form, and
then using the value returned

' acDialog will stop the code until the form is closed
Docmd.OpenForm "NewFormName",,,,,acDialog
If MyValue = 0 Then
MsgBox "You need t select a model"
Else
MyCondition = "[FieldNameInTable]=" & MyValue
Docmd.OpenReport "ReportName", , , MyCondition
End If

--
Good Luck
BS"D


Zaheer said:
Thanks Cohen, its really help me. but i dont want to create a combo in the
form, i only want to combo box appear when i press the command button for
report. any idea how to do this
--
Zaheer
Acesss Database Designer
Planning Supervisor


Ofer Cohen said:
In the form where you have a button to open the report create a combo for the
user to select a value before you try to open the report, then try something
like

Dim MyCondition As String
If IsNull(Me.[ComboName]) Then
MsgBox "You need t select a model"
Else
MyCondition = "[FieldNameInTable=" & Me.[ComboName]
Docmd.OpenReport "ReportName", , , MyCondition
End If

Note: If the value passed to the report is a string use
MyCondition = "[FieldNameInTable='" & Me.[ComboName] & "'"

Adding single quote to the string
--
Good Luck
BS"D


:

i need to generate a report after clicking the item in the combo box. e.g i
put a command button on the form for a report. when i click it, a combo box
should appear and i should select a item from it. On the base of selected
item, it should generate a report, e.g i need a report about the car based on
the model. when i click command button for report , a combo box appear with
the different model like toyota , gmc, lexus etc. and and when i click any
model , it should generate the report from the selected model...... i hope
you understand what i want. thanks
 

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