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??!!!
7 2097
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
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!!
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?
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...
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. -
-
Dim strWhere As String
-
-
If Me.chkSports Then
-
strWhere = strWhere & " AND Sports = True"
-
End If
-
If Me.chkMovies Then
-
strWhere = strWhere & " AND Movies = True"
-
End If
-
If Me.chkInternet Then
-
strWhere = strWhere & " AND Internet = True"
-
End If
-
If Me.chkMotors Then
-
strWhere = strWhere & " AND Motors = True"
-
End If
-
-
If strWhere <> "" Then
-
strWhere = Mid(strWhere, 6)
-
Docmd.OpenForm "form3", acNormal, , strWhere, acEdit
-
Else
-
Msgbox "You haven't selected anything to filter by!"
-
End If
-
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. -
-
Dim strWhere As String
-
-
If Me.chkSports Then
-
strWhere = strWhere & " AND Sports = True"
-
End If
-
If Me.chkMovies Then
-
strWhere = strWhere & " AND Movies = True"
-
End If
-
If Me.chkInternet Then
-
strWhere = strWhere & " AND Internet = True"
-
End If
-
If Me.chkMotors Then
-
strWhere = strWhere & " AND Motors = True"
-
End If
-
-
If strWhere <> "" Then
-
strWhere = Mid(strWhere, 6)
-
Docmd.OpenForm "form3", acNormal, , strWhere, acEdit
-
Else
-
Msgbox "You haven't selected anything to filter by!"
-
End If
-
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!!
JKing 1,206
Recognized Expert Top Contributor
You're quite welcome. Glad it worked out for you.
Jking
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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,...
|
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...
|
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...
| |
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:...
|
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...
|
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....
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |