Filter using combo boxes that are not null
Filter using combo boxes that are not null
(OP)
I want to apply filter criteria to a query using VBA what the user chooses from any selected combo boxes. The boxes on the form are: County, Block, Section, Well #, and Owner from a tale called tblWllInfo. If the user chooses criteria from County and Section...that would be the filter or if the user chooses Block and Owner then that would be the filter. I'm trying to get away from writing seperate SQL for each instance. I would like to use only one SQL statement for the operation. Can anyone help me out here?
RE: Filter using combo boxes that are not null
dim strSQL as string
strSQL= "SElect....... WHERE"
if not(isnull(me!cboYourCountyComboboxName)) then
strsql= strsql & " County = " & me!cboYourCountyComboboxName & " AND "
end if
if not(isnull(me!cboYourBlockComboboxName)) then
strsql= strsql & " Block = " & me!cboYourBlockComboboxName & " AND "
end if
etc....
You will need to examine your SQL to make sure you built it correctly and you will have to get rid of the final AND, but that should get you started in the right direction.
Kathryn
RE: Filter using combo boxes that are not null