Here is my long block of code. Thank you very much.
If IsNull(Me.combomake) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]&[carlaunchquarter]&[carlaunchyear] =[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[carstatus]& [carlaunchquarter]& [carlaunchyear] =[forms]!
[Fcar_outputscreen]![combomake]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[caryear]& [carlaunchquarter]& [carlaunchyear] =[forms]!
[Fcar_outputscreen]![combomake]&[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]& [carMake]& [carlaunchyear] =[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combomake]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]& [carMake]& [carlaunchquarter] =[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combomake]&[forms]!
[Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combomake) And IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carstatus]&
[carlaunchquarter]& [carlaunchyear] =[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carlaunchquarter]& [carlaunchyear]=[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]& [carlaunchyear]=[forms]![Fcar_outputscreen]!
[combomodelyear]&[forms]![Fcar_outputscreen]![combostatus]
&[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]& [carlaunchquarter]=[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combomodelyear) And IsNull(Me.combostatus)
Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[carlaunchquarter]& [carlaunchyear]=[forms]!
[Fcar_outputscreen]![combomake]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomodelyear) And IsNull(Me.combomake) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carstatus]&
[carlaunchquarter]& [carlaunchyear]=[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomodelyear) And IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[carStatus]& [carlaunchyear]=[forms]![Fcar_outputscreen]!
[combomake]&[forms]![Fcar_outputscreen]![combostatus]&
[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomodelyear) And IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[carStatus]& [carlaunchquarter]=[forms]!
[Fcar_outputscreen]![combomake]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combostatus) And IsNull(Me.combomake) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carlaunchquarter]& [carlaunchyear]=[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combostatus) And IsNull(Me.combomodelyear)
Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[carlaunchquarter]& [carlaunchyear]=[forms]!
[Fcar_outputscreen]![combomake]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combostatus) And IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[caryear]& [carlaunchyear]=[forms]![Fcar_outputscreen]!
[combomake]&[forms]![Fcar_outputscreen]![combomodelyear]&
[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combostatus) And IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[caryear]& [carlaunchquarter]=[forms]![Fcar_outputscreen]!
[combomake]&[forms]![Fcar_outputscreen]![combomodelyear]&
[forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combodate) And IsNull(Me.combomake) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]& [carlaunchyear]=[forms]![Fcar_outputscreen]!
[combomodelyear]&[forms]![Fcar_outputscreen]![combostatus]
&[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combodate) And IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[carstatus]& [carlaunchyear]=[forms]![Fcar_outputscreen]!
[combomake]&[forms]![Fcar_outputscreen]![combostatus]&
[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combodate) And IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[caryear]& [carlaunchyear]=[forms]![Fcar_outputscreen]!
[combomake]&[forms]![Fcar_outputscreen]![combomodelyear]&
[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combodate) And IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[caryear]& [carstatus]=[forms]![Fcar_outputscreen]!
[combomake]&[forms]![Fcar_outputscreen]![combomodelyear]&
[forms]![Fcar_outputscreen]![combostatus]"
End If
If IsNull(Me.comboyear) And IsNull(Me.combomake) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]& [carlaunchquarter]=[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.comboyear) And IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[carstatus]& [carlaunchquarter]=[forms]!
[Fcar_outputscreen]![combomake]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.comboyear) And IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[caryear]& [carlaunchquarter]=[forms]![Fcar_outputscreen]!
[combomake]&[forms]![Fcar_outputscreen]![combomodelyear]&
[forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.comboyear) And IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[caryear]& [carstatus]=[forms]![Fcar_outputscreen]!
[combomake]&[forms]![Fcar_outputscreen]![combomodelyear]&
[forms]![Fcar_outputscreen]![combostatus]"
End If
If IsNull(Me.combomake) And IsNull(Me.combomodelyear) And
IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carlaunchquarter
]& [carlaunchyear]=[forms]![Fcar_outputscreen]![combodate]
&[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.combomodelyear) And
IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carstatus]&
[carlaunchyear]=[forms]![Fcar_outputscreen]![combostatus]&
[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.combomodelyear) And
IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carstatus]&
[carlaunchquarter]=[forms]![Fcar_outputscreen]!
[combostatus]&[forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combomake) And IsNull(Me.combostatus) And
IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carlaunchyear]=[forms]![Fcar_outputscreen]!
[combomodelyear]&[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.combostatus) And
IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carlaunchquarter]=[forms]![Fcar_outputscreen]!
[combomodelyear]&[forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combomake) And IsNull(Me.combodate) And
IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]=[forms]![Fcar_outputscreen]![combomodelyear]&
[forms]![Fcar_outputscreen]![combostatus]"
End If
If IsNull(Me.combomake) And IsNull(Me.combodate) And
IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carlaunchyear]&
[carstatus]=[forms]![Fcar_outputscreen]![comboyear]&
[forms]![Fcar_outputscreen]![combostatus]"
End If
If IsNull(Me.combomake) And IsNull(Me.combodate) And
IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carlaunchyear]&
[caryear]=[forms]![Fcar_outputscreen]![comboyear]&[forms]!
[Fcar_outputscreen]![combomodelyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.comboyear) And
IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carstatus]&
[carlaunchquarter]=[forms]![Fcar_outputscreen]!
[combostatus]&[forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combomake) And IsNull(Me.comboyear) And
IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carlaunchquarter]=[forms]![Fcar_outputscreen]!
[combomodelyear]&[forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combomake) And IsNull(Me.comboyear) And
IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]=[forms]![Fcar_outputscreen]![combomodelyear]&
[forms]![Fcar_outputscreen]![combostatus]"
End If
If IsNull(Me.combomodelyear) And IsNull(Me.combostatus)
And IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[carlaunchyear] = [forms]![Fcar_outputscreen]![combomake]&
[forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomodelyear) And IsNull(Me.combostatus)
And IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[carlaunchquarter] = [forms]![Fcar_outputscreen]!
[combomake]&[forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combostatus) And IsNull(Me.combodate) And
IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[caryear] = [forms]![Fcar_outputscreen]![combomake]&
[forms]![Fcar_outputscreen]![combomodelyear]"
End If
If IsNull(Me.combostatus) And IsNull(Me.combodate) And
IsNull(Me.combomake) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carlaunchyear]&
[caryear] = [forms]![Fcar_outputscreen]![comboyear]&
[forms]![Fcar_outputscreen]![combomodelyear]"
End If
If IsNull(Me.combostatus) And IsNull(Me.combodate) And
IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carlaunchyear]&
[carmake] = [forms]![Fcar_outputscreen]![comboyear]&
[forms]![Fcar_outputscreen]![combomake]"
End If
If IsNull(Me.combodate) And IsNull(Me.comboyear) And
IsNull(Me.combomake) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus] = [forms]![Fcar_outputscreen]![combomodelyear]
&[forms]![Fcar_outputscreen]![combostatus]"
End If
If IsNull(Me.combodate) And IsNull(Me.comboyear) And
IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[carstatus] = [forms]![Fcar_outputscreen]![combomake]&
[forms]![Fcar_outputscreen]![combostatus]"
End If
If IsNull(Me.combodate) And IsNull(Me.comboyear) And
IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake]&
[caryear] = [forms]![Fcar_outputscreen]![combomake]&
[forms]![Fcar_outputscreen]![combomodelyear]"
End If
If IsNull(Me.comboyear) And IsNull(Me.combomake) And
IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carstatus]&
[carlaunchquarter] = [forms]![Fcar_outputscreen]!
[combostatus]&[forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.comboyear) And IsNull(Me.combomake) And
IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carlaunchquarter] = [forms]![Fcar_outputscreen]!
[combomodelyear]&[forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.comboyear) And IsNull(Me.combomake) And
IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carstatus]&
[caryear] = [forms]![Fcar_outputscreen]![combostatus]&
[forms]![Fcar_outputscreen]![combomodelyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.combomodelyear) And
IsNull(Me.combostatus) And IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carlaunchyear]
= [forms]![Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.combomodelyear) And
IsNull(Me.combostatus) And IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carlaunchquarter
] = [forms]![Fcar_outputscreen]![combodate]"
End If
If IsNull(Me.combomake) And IsNull(Me.combomodelyear) And
IsNull(Me.combodate) And IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carstatus] =
[forms]![Fcar_outputscreen]![combostatus]"
End If
If IsNull(Me.combomake) And IsNull(Me.comboyear) And
IsNull(Me.combostatus) And IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear] =
[forms]![Fcar_outputscreen]![combomodelyear]"
End If
If IsNull(Me.combomodelyear) And IsNull(Me.comboyear) And
IsNull(Me.combostatus) And IsNull(Me.combodate) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carmake] =
[forms]![Fcar_outputscreen]![combomake]"
End If
If Not IsNull(Me.combomake) And Not IsNull
(Me.combomodelyear) And Not IsNull(Me.combostatus) And
Not IsNull(Me.combodate) And Not IsNull(Me.comboyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[caryear]& [carstatus]& [carlaunchquarter]&
[carlaunchyear] =[forms]![Fcar_outputscreen]![combomake]&
[forms]![Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.carMake) And IsNull(Me.carModel) And IsNull
(Me.caryear) And IsNull(Me.carstatus) And IsNull
(Me.carlaunchquarter) And IsNull(Me.carlaunchyear) And
IsNull(Me.carsegment) Then
MsgBox "Sorry, no matching records."
Cancel = True
End If
Me.Form.Refresh
-----Original Message-----
Calvin,
Can you post your actual code and I'll have a look.
Oops.. I just noticed that within my second loop you don't need the " & " at
the end of the concatenation line.
HTH
Sam
I have tried your suggestion, it doesn't filter any
results. Anything I should have done more here.
thx
-----Original Message-----
You could name your combo boxes in such a way that they
can be accessed like
an array. For example cbo1, cbo2, cbo3, etc... Set the
tag property of each
combo box to the name of the field they match in the
underlying query of the
report, eg. set the tag property of combomodelyear
(which is now named cbo1)
to caryear.
Now you can create the where clause within two loops...
Dim ct as integer
Dim NumCbo as integer
Dim WhereClause as string
WhereClause=""
NumCbo=5
For ct=1 to NumCbo
If Not(IsNull(Me("cbo" & ct))) then
WhereClause=WhereClause & Me("cbo" & ct).tag & "
& "
Endif
Next
WhereClause=WhereClause & " = "
For ct=1 to NumCbo
If Not(IsNull(Me("cbo" & ct))) then
WhereClause=WhereClause & Me("cbo" & ct) & " & "
Endif
Next
DoCmd.OpenForm "Fcar_outputscreen", , , WhereClause
I haven't tested the above code, but it should
illustrate the idea.
HTH
Sam
message
Hi,
I have developed a form/subform with multiple combo
boxes
(a total of five). A user can perform cross- searching
using these combo boxes by pressing a command button.
On
the command button, I have put in the code below. It
works fine at the moment, but now I want to more combo
boxes, which will further lengthen the code. I wonder
if
there is a better way of doing it.
P.S. I only put a small part of the code
If IsNull(Me.combomake) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carstatus]&[carlaunchquarter]&[carlaunchyear] =
[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomodelyear) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carMake]&
[carstatus]& [carlaunchquarter]& [carlaunchyear] =
[forms]!
[Fcar_outputscreen]![combomake]&[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomake) And IsNull (Me.combomodelyear)
Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[carstatus] &
[carlaunchquarter]& [carlaunchyear] =[forms]!
[Fcar_outputscreen]![combostatus]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
If IsNull(Me.combomake) And IsNull(Me.combostatus) Then
DoCmd.OpenForm "Fcar_outputscreen", , , "[caryear]&
[carlaunchquarter]& [carlaunchyear]=[forms]!
[Fcar_outputscreen]![combomodelyear]&[forms]!
[Fcar_outputscreen]![combodate]&[forms]!
[Fcar_outputscreen]![comboyear]"
End If
.
.