473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Combobox Select All option

124 100+
I have an unbound combobox (cboFilterMatricYT) to filter records on a form. I've added the "All" selection to the combobox's rowsource using UNION. In the AfterUpdate event of the combobox I have the following:

Expand|Select|Wrap|Line Numbers
  1.     Me.RecordSource = "SELECT Disc.* FROM Disc INNER JOIN MatricYT ON Disc.MatricId=MatricYT.MatricId WHERE Disc.MatricId = " & Me.cboFilterMatricYT & " ORDER BY MatricYT.MatricYear DESC , MatricYT.MatricTerm, Disc.SortOrder;"
  2.     Me.Requery
  3.  
What I can't figure out is how to get this to process the All selection. Any suggestions?
May 25 '10 #1

✓ answered by patjones

Try this (replace 99 with whatever your ID for the All option is):

Expand|Select|Wrap|Line Numbers
  1. Dim rst As DAO.Recordset
  2. Dim strSQL As String, strFilter As String
  3.  
  4. lngMatricIdFrom = Me.cboFilterMatricYT
  5.  
  6. strFilter = IIf(lngMatricIdFrom = 99, "", "WHERE MatricId = " & lngMatricIdFrom)
  7. strSQL = "SELECT * FROM DegReq " & strFilter
  8.  
  9. Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)

What OldBirdman and I posted previously is VBA, by the way. This is what I meant in saying that there are several ways to do this.

Pat

8 2866
patjones
931 Expert 512MB
You could try something like this:

Expand|Select|Wrap|Line Numbers
  1. Me.RecordSource = "SELECT Disc.* FROM Disc INNER JOIN MatricYT ON Disc.MatricId = MatricYT.MatricId ORDER BY MatricYT.MatricYear DESC , MatricYT.MatricTerm, Disc.SortOrder;"
  2.  
  3. If Me.cboFilterMatricYT <> 'All' Then
  4.      Me.Filter = "Disc.MatricId = " & Me.cboFilterMatricYT
  5.      Me.FilterOn = True
  6. End If
  7.  
  8. Me.Requery

You'll need to replace 'All' with whatever ID you assigned to that entry in the combo box. There are certainly other ways to do this, I would add.

Pat
May 25 '10 #2
OldBirdman
675 512MB
If conditions change, you need an "Else" clause to ignore the old filter or deactivate it.
Expand|Select|Wrap|Line Numbers
  1. If Me.cboFilterMatricYT <> 'All' Then 
  2.      Me.Filter = "Disc.MatricId = " & Me.cboFilterMatricYT 
  3.      Me.FilterOn = True 
  4. Else
  5.      Me.FilterOn = False 
  6.      'Note: Me.Filter = "" will work here also
  7. End If 
  8.  
  9. Me.Requery 
May 25 '10 #3
bullfrog83
124 100+
@zepphead80
Thanks! That worked. However, now I need to know how to do this in VBA because I need to query a recordset. So, now its:

Expand|Select|Wrap|Line Numbers
  1. lngMatricIdFrom = Me.cboFilterMatricYT
  2. rst = CurrentDb.OpenRecordset("SELECT * FROM DegReq WHERE MatricId = " & lngMatricIdFrom, dbOpenSnapshot)
  3.  
How would I get this to process all MatricId's if "All" is selected?
May 25 '10 #4
patjones
931 Expert 512MB
@OldBirdman
Quite right you are. Thank you!
May 25 '10 #5
bullfrog83
124 100+
@OldBirdman
Thanks Birdman! When I was testing out the code I saw that I needed that Else clause.
May 25 '10 #6
patjones
931 Expert 512MB
Try this (replace 99 with whatever your ID for the All option is):

Expand|Select|Wrap|Line Numbers
  1. Dim rst As DAO.Recordset
  2. Dim strSQL As String, strFilter As String
  3.  
  4. lngMatricIdFrom = Me.cboFilterMatricYT
  5.  
  6. strFilter = IIf(lngMatricIdFrom = 99, "", "WHERE MatricId = " & lngMatricIdFrom)
  7. strSQL = "SELECT * FROM DegReq " & strFilter
  8.  
  9. Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)

What OldBirdman and I posted previously is VBA, by the way. This is what I meant in saying that there are several ways to do this.

Pat
May 25 '10 #7
bullfrog83
124 100+
@zepphead80
I suspected it might be something to that effect. Now that I reread my question I realize that I incorrectly stated it as I did understand what you and OldBirdman provided was vba. The Me.Filter worked great for form filtering; clean and efficient. I just wasn't sure how to do the same thing for a query in vba. Thanks again!
May 26 '10 #8
NeoPa
32,556 Expert Mod 16PB
Filter strings in Access are generally equivalent to the WHERE clause of a SQL query, but missing the actual word WHERE.

Hence, if you have a string variable (EG. strFilter) you canm use this as is, to pass as a filter parameter for opening forms or reports, but you can also add it into the SQL for a simple (non-filtered) query by using code similar to :
Expand|Select|Wrap|Line Numbers
  1. strSQL = strSQL & " WHERE " & strFilter
May 26 '10 #9

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

Similar topics

1
by: Michael Hoffmann | last post by:
Hello, As you might guess I am completely new to this language. Maybe I get some help here. I try to execute a user defined funciton from a select option in a document to read a file into an...
9
by: Programatix | last post by:
Hi, I'm having problem with ComboBox. I'm trying to force the ComboBox select nothing by doing this, myCombo.SelectedText = "" myCombo.SelectedIndex = -1 but in vain, as the ComboBox will...
3
by: J. Muenchbourg | last post by:
I have an ASP admin script where I'm adding records, and I have a category that already has set name values hard-coded into a selct option pulldown, but if the user wants to create a new category...
4
by: Jeff Anderson | last post by:
Is there a style for a select option's "selected" color? For example: <HTML> <BODY> <FORM NAME="form1"> <SELECT NAME="mySelect" SIZE="7" style="background-color:red;"> <OPTION>Test 1...
4
by: Old Lady | last post by:
Hi, I need help! I have a SELECT/OPTION list. My goal is to have a TEXT input field in a form that is normally disabled, but it should become enabled when the user select one predefined OPTION....
11
by: Stefan Finzel | last post by:
Hi trying to remove one or all elements of select options fails for Pocket Internet Explorer. Is there a way to do this? if is_PIE { // this does not work on Pocket IE while (opt.length) {...
2
by: shagy | last post by:
Hi, I'm having a problem with a <select><option> which has white space in values... When I post the data I only get the first word (up to the white space). "Testing white space" becomes...
1
by: kirke | last post by:
I want to load textarea's value in drop-down box. In first page, such form is existed. <form name="form1" method="post" action="next.php"> <textarea name="dayList" Id = "dayList" cols=20...
3
by: pravinnweb | last post by:
Hi i have select option in my page which works fine in firefox in which i mention specific width for select option when i clicked select list the option lengths are large the option area is expanded...
7
by: fsalvador | last post by:
Hi, I am trying to figure it out how to to hide in onmouseout the select options of a form. Below is the code I got so far. It isn't working. Please help. Thanks <!DOCTYPE HTML PUBLIC...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
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,...
0
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...
0
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
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...

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.