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 2122
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.Rec ordSource = 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
FirstName/LastName/email?
Or is it possible to allow this but to throw up an alert message? Warning
that this person is probably already in the database? TIA
|
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 unless I need that for some
reason, which there are reasons. I need a bound or unbound check box
that would be clicked to cheeck for duplicate records once i type in a
company name and leave that field. I need this to be able to view that
company...
|
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, forms, queries and even
inter link.
The database records support for a cohort of schools, giving the
ability to give summaries of support by consultant, subject etc. So far
all is going well with data being inputted by way of a school support
|
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 Product is sold, any users
who have that boxed checked will get a notification. So my (shortened)
database layout is as such:
Product Table
ProductID (PK)
ProductName
|
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 of the form which is
submit and cancel. After i have clicked submit, the information is
stored directly into my corresponding database table. My problem here
is i need to retrieve back the information submitted to display all the
data that the...
| |
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:
SELECT @SQLString = N'INSERT INTO TMP_UR_Randoms(Admit_DOCID,
Client_ID, SelectDate, SelectType,RecordChosen)'
SELECT @SQLString = @SQLString + N'(SELECT TOP ' + @RequFilesST + '
Admit_DOCID, Client_ID, SelectDate, SelectType, RecordChosen...
|
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 (values are check or credit card)...to store the payment type. What I'm looking for is a way to pop up a form based off either a credit card or a check selection. Either form would then store their data into the Payments table (used for report...
|
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.
how can i do that using php. if any one havin code for that please help me
thanks
|
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 which were successful. I have been able to display the required value in a ‘text box’ which is a little helpful but not ideal.
I have a table called tblLogSheet. The ‘Description’ field of this table uses a lookup table called...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |