Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo boxes

Status
Not open for further replies.

bruno1

Technical User
Dec 10, 2005
8
ES
I have two synchronised combo boxes. Sometimes I want to print a report with nothing in the 2nd dependant combo.But if I leave it blank the whole report appears blank. How do I overcome this?
 
Sorry, my ESP always takes a day of rest on Sundays! I'm afraid you'll have to give us a bit more information than you have so far, like what the data in the combobxes is (including datatype) and exactly what it is that you're trying to do.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Yes was a bit vague.
The two combo boxes are based on two tables group and title and the code for them is
Private Sub group_AfterUpdate()
Me.Title.RowSource = "SELECT TitleName FROM" & _
" Title WHERE GroupID = " & Me.group & _
" ORDER BY TitleName"
Me.Title = Me.Title.ItemData(0)

The combos work fine.But sometimes there is an item in the group table that does not have an entry in the title table. I can fill in the form leaving the title entry blank, but when I come to print the report which is based on a query using the group and title tables any records on the form with the title blank do not print
 
In your Report's Recordsource you can put put criteria, or if you are opening the report from a button on a form, you can build a WHERE statement and open the report using it. So for example:

BUTTON'S ONCLICK EVENT:
Code:
dim strWHERE
strWHERE = "[FieldName1] = " & Me.Combo1
If not isnull(Me.Combo2) then strWHERE = strWHERE & " and [FIeldName2] = " & Me.Combo2

Docmd.OpenReport "ReportName",acviewpreview,,strWhere

So only if combo2 is not null will the WHERE statment include it; otherwise it won't consider it.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Or

You could have an "ALL" condition, somthing like so:

Me.Title.RowSource = "SELECT TitleName FROM" & _
" Title WHERE GroupID = " & Me.group & _
"UNION " & _
"SELECT "*" As A FROM Title " & _
" ORDER BY TitleName"
Me.Title = Me.Title.ItemData(0)

and make your criteria LIKE insead of an Equal to


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks for replying,
Ginger in the code what do I put for Combo1 and Combo2?

Ken,
After trying what you said I get run time error 13 type mis match. Any suggestions?
 
Thanks Ginger but the combo boxes are on a sub form and the command button is on the main form and I don´t know how to reference the code on the main form to the sub form
 
Forms![MainformName]![SubFormName]![SubFormcontrol]

or

me![SubFormName]![SubFormcontrol]

HTH.
 
To everyone that has helped me thanks. I have not quite solved my problem but thanks to you all I feel that I am almost there.
Just something minor that I am doing wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top