Using a Search Form with Checkboxes to Filter Main Form

  • Thread starter cscotty via AccessMonster.com
  • Start date
C

cscotty via AccessMonster.com

Hello all. I did some searching and did find some solutions to my problem,
but I couldnt understand them. Here we go:

I have a form named "frmSearch" that has 3 Combo boxes and 15 checkboxes.
When I select the first combo box, it filters the data in the second.
Similarly, the second combo box filters the third. After my combo boxes are
my three rows of five checkboxes.

After I did my initial filter using the combo boxes, I would like to check
some of the checkboxes and perform a search. The search would display the
resutling records which fileds correspond to the boxes that were checked.
For example, if I checked boxes chbxBlue, chbxGreen, and chbxRed, I would
want to return all cars that are blue, green, and red.

I do not have any code, becuase I do not know where to start. If possible,
please try to use the example above to help me.

Many Thanks,
Scott
 
D

Dorian

Sounds like you need to build a query based on the value of the checkboxes.
Ypu are going to need to know how to code a query from VBA.
You will start with something like:
strSQL = "SELECT * FROM tblCARS WHERE"
then you will add for each checkbox
IF cbo1 = True Then
strSQL = strSQL & " CarColor = 'Blue' AND "
END IF
IF cbo2 = True Then
strSQL = strSQL & " CarColor = 'Gray' AND"
END IF
at the end of processing all checkboxes you will need to delete the last
'AND' from the string and then run the query.
There are many different ways to do this, this is just one of them.

Where are you expecting to see the results of your search?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
J

John W. Vinson

IF cbo1 = True Then
strSQL = strSQL & " CarColor = 'Blue' AND "
END IF
IF cbo2 = True Then
strSQL = strSQL & " CarColor = 'Gray' AND"

Just a warning - this (as written) will ensure that you get NO hits on your
query. The CarColor field can have only one value; if it's 'Blue' then it's
not 'Grey', and the AND operator requires that both criteria be true!

Don't you mean "OR" instead of "AND"?
 
C

cscotty via AccessMonster.com

Dorian said:
Sounds like you need to build a query based on the value of the checkboxes.
Ypu are going to need to know how to code a query from VBA.
You will start with something like:
strSQL = "SELECT * FROM tblCARS WHERE"
then you will add for each checkbox
IF cbo1 = True Then
strSQL = strSQL & " CarColor = 'Blue' AND "
END IF
IF cbo2 = True Then
strSQL = strSQL & " CarColor = 'Gray' AND"
END IF
at the end of processing all checkboxes you will need to delete the last
'AND' from the string and then run the query.
There are many different ways to do this, this is just one of them.

Where are you expecting to see the results of your search?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
Hello all. I did some searching and did find some solutions to my problem,
but I couldnt understand them. Here we go:
[quoted text clipped - 15 lines]
Many Thanks,
Scott


Thanks for the help! I'm trying to get this, but it doesnt seem that I am.
Perhaps if I explain it a little better it would make more sense. Please
disregard the previous example. This is the actual example that I am working
with....I have posted a link to a picture of my search form (frm03Search)

http://www.geocities.com/cscott784/dbase2.bmp

I have a form titled "frm01Index" that has an option group named "frmsevFind"
that tells the severity level of an audit. The three levels are Minor, Major,
and Critical( Values 1, 2, 3 respectively). The option group uses option
buttons and the Control Source of the group is linked to tbl00Index.[sevFind].


I have a second form named "frm03Search". As a search criteria, I use a
checkbox that indicates the severity level of an audit to search for. So
there would be a checkbox next to "Minor", "Major", and "Critical" on the
frm03Search form. This form also has 3 combo boxes named "cboNum",
"cboInves", and "cboSite". I currently use a query for the row source to
filter the second and third combo boxes.

If you look at my form, what I would like to do is select the first combo box,
the second combo box, and the thrid combo box. Then I would like to select a
checkbox (lets say "minor") from the "Severity of Findings" criteria on the
form. Then I would like to click the "search" button, and have the search
return all the records from "frm01Index" that has the values in the three
combo boxes, and the "Minor" option button selected for sevFind. Then it
should present itself in a form identical to my frm01Index (sorry I didnt
post a pic of it).

I really hope this helps in understanding my issue. If you can help me, I
will greatly appreciate it. Please let me know if further info is required.

Thanks!
Scott
 
C

cscotty via AccessMonster.com

cscotty said:
Sounds like you need to build a query based on the value of the checkboxes.
Ypu are going to need to know how to code a query from VBA.
[quoted text clipped - 21 lines]
Thanks for the help! I'm trying to get this, but it doesnt seem that I am.
Perhaps if I explain it a little better it would make more sense. Please
disregard the previous example. This is the actual example that I am working
with....I have posted a link to a picture of my search form (frm03Search)

http://www.geocities.com/cscott784/dbase2.bmp

I have a form titled "frm01Index" that has an option group named "frmsevFind"
that tells the severity level of an audit. The three levels are Minor, Major,
and Critical( Values 1, 2, 3 respectively). The option group uses option
buttons and the Control Source of the group is linked to tbl00Index.[sevFind].

I have a second form named "frm03Search". As a search criteria, I use a
checkbox that indicates the severity level of an audit to search for. So
there would be a checkbox next to "Minor", "Major", and "Critical" on the
frm03Search form. This form also has 3 combo boxes named "cboNum",
"cboInves", and "cboSite". I currently use a query for the row source to
filter the second and third combo boxes.

If you look at my form, what I would like to do is select the first combo box,
the second combo box, and the thrid combo box. Then I would like to select a
checkbox (lets say "minor") from the "Severity of Findings" criteria on the
form. Then I would like to click the "search" button, and have the search
return all the records from "frm01Index" that has the values in the three
combo boxes, and the "Minor" option button selected for sevFind. Then it
should present itself in a form identical to my frm01Index (sorry I didnt
post a pic of it).

I really hope this helps in understanding my issue. If you can help me, I
will greatly appreciate it. Please let me know if further info is required.

Thanks!
Scott

Any dice?
 

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