If Statement Code Help Needed

D

Dave Elliott

On my form there is a a combo box named Combo32 that shows a list of
customers
If there is a customer chosen from this list, I need the report to open and
show only that customer, else show all records.
The report is named RLabels The control in query is named
Customers, i.e. table control is also Customers
Do I also have to put a condition statement in the query that is used for
the report?
How can I do this??
 
D

Dirk Goldgar

Dave Elliott said:
On my form there is a a combo box named Combo32 that shows a list
of customers
If there is a customer chosen from this list, I need the report to
open and show only that customer, else show all records.
The report is named RLabels The control in query is named
Customers, i.e. table control is also Customers
Do I also have to put a condition statement in the query that is used
for the report?
How can I do this??

Is your report opened from VBA code behind the form that holds the combo
box? If so, you could use code patterned on this example:

If IsNull(Me!Combo32) Then
DoCmd.OpenReport "RLabels", acViewPreview
Else
DoCmd.OpenReport "RLabels", acViewPreview, _
WhereCondition:="Customers=""" & Me!Combo32 & """"
End If

That assumes that you are telling the truth when you say the field
("control in query") is named "Customers" -- not "Customer", as I'd
expect, and also that this is a text field, not a number. If it's a
numeric customer number, change the WhereCondition to

"Customers=" & Me!Combo32

Note that I've also assumed you want to open this report for previewing,
not to print it directly. If you want to print it without previewing,
delete ", acViewPreview".
 

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