If Statement Code Help Needed

  • Thread starter Thread starter Dave Elliott
  • Start date Start date
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??
 
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".
 
Back
Top