473,487 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fiter records based on check box selection

4 New Member
Hi!!!

I´m used to search your forum all the time if I have any problem in Java, C, etc,etc... and I always found an answer, but this time I can´t...

I know that this must be a simple answer, but I just can´t figure it out!

I´m doing a simple, simple, extremelly simple Access 2003 database and I´m stuck at a filtering problem.

1 - The users fill out a form with different check boxes for each record (among other fields)
2 - I want a user to be able to search on the main window, filling out the check boxes he wants to search and pressing a button, the records that correspond to the check boxes filled.


Example:

Form1 containing:

Name: txtbox
Age: txtbox
Occupation: txtbox

Hobbies: Sports: chkbox Movie:chkbox Internet:chkbox
Motors: chkbox

Form2 (Main Window) containg:

Button1 to insert a new record (sends you to Form1).
Button2 to change/delete a record (sends you to a clone of Form1 - let´s call it Form3)

The checkboxes Sports, Movie, Internet and Motors
And a button that (should) filters the records through the checkboxes he checked and present you Form3 filtered.


I know this is confusing, but I stink at explaining things!!

I´ve tried VBA code, SQL (through the RecordSource), Macros... I´ve tried everything I know and nothing :( !

Can anyone help me please??!!!
Aug 1 '07 #1
7 2097
abolos
65 New Member
Hi!!!

I´m used to search your forum all the time if I have any problem in Java, C, etc,etc... and I always found an answer, but this time I can´t...

I know that this must be a simple answer, but I just can´t figure it out!

I´m doing a simple, simple, extremelly simple Access 2003 database and I´m stuck at a filtering problem.

1 - The users fill out a form with different check boxes for each record (among other fields)
2 - I want a user to be able to search on the main window, filling out the check boxes he wants to search and pressing a button, the records that correspond to the check boxes filled.


Example:

Form1 containing:

Name: txtbox
Age: txtbox
Occupation: txtbox

Hobbies: Sports: chkbox Movie:chkbox Internet:chkbox
Motors: chkbox

Form2 (Main Window) containg:

Button1 to insert a new record (sends you to Form1).
Button2 to change/delete a record (sends you to a clone of Form1 - let´s call it Form3)

The checkboxes Sports, Movie, Internet and Motors
And a button that (should) filters the records through the checkboxes he checked and present you Form3 filtered.


I know this is confusing, but I stink at explaining things!!

I´ve tried VBA code, SQL (through the RecordSource), Macros... I´ve tried everything I know and nothing :( !

Can anyone help me please??!!!

In your case you may use the SELECT SQL statement. Give it a try.
Abolos
Aug 1 '07 #2
PANGAWD
4 New Member
In your case you may use the SELECT SQL statement. Give it a try.
Abolos
I´ve already tried

SELECT * FROM "Table" WHERE "Field" = True

and

SELECT * FROM "Table" WHERE "Field" And "Field2" And "Field3" = True

but the problem is that the field of the search isn´t always True and you can´t put variables in the SQL statement... (through VBA) like

************************************************** *************************************
Dim MySQL As String

If ([Field from Form2] = True) Then
MySQL = "SELECT * FROM Table Where [Field from Table]=True;"
End If <--(Just one check among several)

DoCmd.OpenForm "Form3", acNormal, , , acFormEdit, acWindowNormal
Forms!Form3.RecordSource = MySQL
************************************************** **************************************

And this only works for one check search, if you select two options to search (more "If") it will "erase" the first and search only the last one as the MySQL variable is just one...

Thx!!
Aug 1 '07 #3
JKing
1,206 Recognized Expert Top Contributor
There are a few things you can do in VBA to get around this.

Just a little information to start though. If say the user checks Sports and Movies do you want to bring up only those persons where their hobbies are sports and Movies or do you want to show persons that may only like sports or may only like Movies?
Aug 1 '07 #4
PANGAWD
4 New Member
There are a few things you can do in VBA to get around this.

Just a little information to start though. If say the user checks Sports and Movies do you want to bring up only those persons where their hobbies are sports and Movies or do you want to show persons that may only like sports or may only like Movies?

All the people that like (checked) Sports AND Movies...
That have checked both "items" on the record...
Aug 1 '07 #5
JKing
1,206 Recognized Expert Top Contributor
What I would suggest is setting the recordsource of Form3 in the design mode property sheet to a query that retrieves all the records and has no Where criteria. Then you can build the criteria and pass it into the Where Statement parameter of the open form command.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim strWhere As String
  3.  
  4. If Me.chkSports Then
  5.     strWhere = strWhere & " AND Sports = True"
  6. End If
  7. If Me.chkMovies Then
  8.     strWhere = strWhere & " AND Movies = True"
  9. End If
  10. If Me.chkInternet Then
  11.     strWhere = strWhere & " AND Internet = True"
  12. End If
  13. If Me.chkMotors Then
  14.     strWhere = strWhere & " AND Motors = True"
  15. End If
  16.  
  17. If strWhere <> "" Then
  18.     strWhere = Mid(strWhere, 6)
  19.     Docmd.OpenForm "form3", acNormal, , strWhere, acEdit 
  20. Else
  21.     Msgbox "You haven't selected anything to filter by!"
  22. End If
  23.  
Aug 1 '07 #6
PANGAWD
4 New Member
What I would suggest is setting the recordsource of Form3 in the design mode property sheet to a query that retrieves all the records and has no Where criteria. Then you can build the criteria and pass it into the Where Statement parameter of the open form command.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim strWhere As String
  3.  
  4. If Me.chkSports Then
  5.     strWhere = strWhere & " AND Sports = True"
  6. End If
  7. If Me.chkMovies Then
  8.     strWhere = strWhere & " AND Movies = True"
  9. End If
  10. If Me.chkInternet Then
  11.     strWhere = strWhere & " AND Internet = True"
  12. End If
  13. If Me.chkMotors Then
  14.     strWhere = strWhere & " AND Motors = True"
  15. End If
  16.  
  17. If strWhere <> "" Then
  18.     strWhere = Mid(strWhere, 6)
  19.     Docmd.OpenForm "form3", acNormal, , strWhere, acEdit 
  20. Else
  21.     Msgbox "You haven't selected anything to filter by!"
  22. End If
  23.  

Txs A LOT, I´ll try It but sounds like it works, never thought of that!!!


DAMN!!! You´re really good!!! Many many many THANKS!!! I wish there would be a way I could repay you!! If you ever come to Portugal be sure to PM me ;)

Once again...Thnx!!
Aug 1 '07 #7
JKing
1,206 Recognized Expert Top Contributor
You're quite welcome. Glad it worked out for you.

Jking
Aug 1 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

9
14550
by: Catherine Jo Morgan | last post by:
Can I set it up so that a certain combination of fields can't contain the same entries, on another record? e.g. a combination of FirstName/LastName/address? Or FirstName/LastName/phone? Or...
1
1544
by: d9pierce | last post by:
Hi all, I have a company form that I would like to protect against duplication unless checked. Main point being, that I dont want to just be able to add a duplicate company name in a test box...
6
1913
by: Dazbear | last post by:
Hi There Have been on a massive learning curve today creating an Access database without having even started the software before this morning! All going well and have learned to create table,...
7
3662
by: Ryan | last post by:
OK, here's my setup. I have a treeview control that is populated with records from a Product table, and it allows "checking". This is used for my automatic notification system. Say a particular...
13
3397
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
3
6023
by: Cindy | last post by:
I'm trying to use the NEWID function in dynamic SQL and get an error message Incorrect syntax near the keyword 'ORDER'. Looks like I can't do an insert with an Order by clause. Here's the code:...
7
3367
imrosie
by: imrosie | last post by:
Hellol, I'm again in need of your help with my Order processing system.. My Order form is based on (query) of Customer and Order tables (includes a subform for the product data)...has a listbox...
7
10053
by: mukeshrasm | last post by:
hello every one i want to delete the selected records from database. selection is based on check box. so when user will select any check box it will delete the corresponding records from database....
6
5164
by: David Wright | last post by:
Hello Folks I am using Microsoft Access 2000 I would be grateful if someone could help me with “Dlookup”. I tried various methods of writing Dlookup and various events to trigger it, none of...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.