Multiple Criteria Off A Listbox
Jun 8, 2007I have a tutorial on how to do this, but they use an SQL code query. Is there anyway to do this by adding some type of criteria to an object query?
View RepliesI have a tutorial on how to do this, but they use an SQL code query. Is there anyway to do this by adding some type of criteria to an object query?
View RepliesHi there. I have a problem with queries that i am creating on the fly with access. My setup is this:
A table called Order which has various fields including a field called Date Taken. The format of this is Date/Time with the format d/m/yyyy.
A form called frmMultiSelect which has a listbox called lstdates and a command button called cmdOpenQuery.
in lstdates the row source is: SELECT DISTINCT Order.[Date Taken] FROM [Order] UNION select "......ALL......" from [Order];
And in the button onClick event i have the following code (adapted from a web source):
Private Sub cmdOpenQuery_Click()
On Error GoTo Err_cmdOpenQuery_Click
Dim MyDB As DAO.Database
Dim qdef As DAO.QueryDef
Dim i As Integer
Dim strSQL As String
Dim strWhere As String
Dim strIN As String
Dim flgSelectAll As Boolean
Dim varItem As Variant
Set MyDB = CurrentDb()
strSQL = "SELECT * FROM [Order]"
'Build the IN string by looping through the listbox
For i = 0 To lstDates.ListCount - 1
If lstDates.Selected(i) Then
If lstDates.Column(0, i) = "......ALL......" Then
flgSelectAll = True
End If
strIN = strIN & "#" & lstDates.Column(0, i) & "#,"
End If
Next i
'Create the WHERE string, and strip off the last comma of the IN string
strWhere = " WHERE [Date Taken]=" & Left(strIN, Len(strIN) - 1)
'If "All" was selected in the listbox, don't add the WHERE condition
If Not flgSelectAll Then
strSQL = strSQL & strWhere
End If
MyDB.QueryDefs.Delete "qryCompanyCounties"
Set qdef = MyDB.CreateQueryDef("qryCompanyCounties", strSQL)
'Open the query, built using the IN clause to set the criteria
DoCmd.OpenQuery "qryCompanyCounties", acViewNormal
'Clear listbox selection after running query
For Each varItem In Me.lstDates.ItemsSelected
Me.lstDates.Selected(varItem) = False
Next varItem
Exit_cmdOpenQuery_Click:
Exit Sub
Err_cmdOpenQuery_Click:
If Err.Number = 5 Then
MsgBox "You must make a selection(s) from the list", , "Selection Required !"
Resume Exit_cmdOpenQuery_Click
Else
'Write out the error and exit the sub
MsgBox Err.Description
Resume Exit_cmdOpenQuery_Click
End If
End Sub
When i open the form and look at the list box the dates are there along with the ......ALL...... however the dates whose day is less than 10 are displayed with the leading 0 e.g 04/12/2005.
When i click the run query command button on one of these dates the query is opened blank. the sql code output is:
SELECT *
FROM [Order]
WHERE [Date Taken]=#04/12/2005#;
If it was changed to 4/12/2005 it works but i dont know why access is putting in this leading 0.
Please help me!! I can send the database if needed
Thanks very much
I have a search form that uses several comboboxes, textboxes and checkboxes that are used as criteria in a query. You enter in the relevant information, hit search and a report opens based on the filtered query.
What I would like to do is change one of these combo boxes to a listbox and use the multiple selection as the query criteria. I know it's not as simple as just putting the listbox as a criteria in the query, and I've also tried many different variations on the varItem and strWhere code.
I have a form which contains a listbox. It is a multi-select listbox. And I have a button on the form which runs a report. But I want the report to only show the selected records from the listbox. The report gets its records from an underlying query. But how do I make the selected records on the listbox become the query criteria?
View 4 Replies View RelatedI have a Access table that stores BatchNo,Scandate,NewBatchNo . As I can't attach Access database here so I have exported data from Access to Excel in Sheet1 to show how the data is stored in Access table.
Now I have to write code in VBA that will check the last NewBatchNo in the table . In the attached workbook its 194389. Now vba code should check the NewBatchNo which are blank before 194389 . Now in the records where NewBatchNo is blank , it should add the corresponding BatchNo,ScanDate in the listbox1 in form1.
e.g Sheet2 in the attached workbook stores Bathcno and Scandate of those records where NewBatchNo is null and before the Last used NewBatchNo which is 194389 in our example.
I need to count records based on multiple criteria from two different tables. I have two tables (i.e. "tblTasks" and "tblTaskHistory"). The tables have a one-to-many relationship based on the "TaskID" field. "tblTasks" has a field called "AssignedTo" and "tblTaskHistory" has a field called "TaskStatus". I need to know how many tasks have been "reopened", the "reopened" status is located in the "TaskStatus" field in "tblTaskHistory". I need this count against a unique listing of employees which can be found in the "AssignedTo" field in "tblTasks".
View 4 Replies View RelatedI have a listbox that uses a query to reference a value in the current form. The problem is for some reason Access is trying to fill this listbox before even showing the form, so I get prompted to manually enter the query criteria when it should be picking it up from the form.
This is bizarre because it's only just started doing it. I've removed the listbox and created it again, but no help. I have listboxes such as this all over the place, but this particular one has just started playing up! Why?
I am attempting to filter records using a multi-select listbox, but all records are being returned. Here is my code.
Private Sub btnKeyboxCount_Click()
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
[Code] ....
I create a list box to store a lsit of groups. It allows user to have multiple selections. I also have a "ALL" is the list. On listbox Click event, I then set up the SQL based on the selection. This SQL will be the query for the report.
If user select "ALL", I want all project to be selected. However, my code always show "SELECT * FROM tbFinancial_grouping
WHERE tbFinancial_grouping.RollUp IN('ALL');" Therefore, nothing is selected.
Could anyone et me know what is wrong about my code? Thank you very much.
Private Sub lsRollUp_Click()
Dim db As DAO.Database
Dim qdf1 As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL1 As String
Set db = CurrentDb()
Set qdf1 = db.QueryDefs("qry_FinancialReport_Selector")
For Each varItem In Me!lsRollUp.ItemsSelected
strCriteria = strCriteria & ",'" & Me!lsRollUp.ItemData(varItem) & "'"
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
If strCriteria = ALL Then
strSQL1 = "SELECT * FROM tbFinancial_grouping;"
Else
strSQL1 = "SELECT * FROM tbFinancial_grouping " & _
"WHERE tbFinancial_grouping.RollUp IN(" & strCriteria & ");"
End If
qdf1.sql = strSQL1
Set db = Nothing
Set qdf1 = Nothing
End Sub
Hi
In my application, I am allowing multiple selection in a listbox.
The data is saved in table. While retrieving, the items that were selected for saving, show as selected. But on printing ListIndex, it prints -1. What could be wrong ? I need to resolve it. Any solution ?
Hi,
I tried putting a multiple select listbox in my access form but I cant put values in it. I want to put values of a table (i.e a field in the table) in the list.
I have selected the microsoft forms 2.0 listbox..
1> How can I put values in it?
2> Is there a way to make the access listbox a multiselect one?
Thanks
I have a listbox with about 8 different choices. i want to be able to query what is selected in this list box but I need to be able to select more than one choice so that my employees don't have to create multiple forms for the same item. Is there any way to select more than one option? It would help greatly even if I have to add code in VB I will figure out how to do it, thank you.
View 2 Replies View RelatedThis must be pretty common but I cann't figure it out.
There is a listbox that multiple selections are allowed. This listbox is bounded with a table field. All selections must be stored. I don't mind if each selection is stored as a different record.
Any ideas?
Hi guys new here.
Here's what I'm trying to do:
I made a listbox in which get's it's source from a field in a table named Soft. The field is named Software1.
This field contains a list off software that could be installed on systems.
I allready can select multiple selections from the listbox but what I want to do is the following.
I want to press a button, and after I press the button I want that the selected Software is added to a new listbox which show the Software installed. The software in the second listbox would also be stored inside a Table so that I could print them out in Reports.
To simply explain what I'm trying to do:
SoftwareListbox >> Make multple selections>>Press button>> Adds selected software to InstalledListbox which stores in the softwarelist installed in a Table.
I really hope you guys understand what I'm trying to do.
And sorry for my bad english, should have paid better attention during English class ;)
Hi,
I have a simple order entry system working with a subform containing combo box where a client selects various products from a table. These are recorded in separate table which allows for subsequent updating of the orders placed.
Now I want to refine this so that the user may make multiple selections as it is a bit laborious making 'n' single selections via a combo based subform.
Only a list box allows multiple selections but I would like some guidance on how to store and be able to recall and update the selected items.
Thanks and Regards
Tony Randell
I am designing a small database.
I have problem in selecting Mutiple list values from list box.
I have a table of Personal.With fields
SrNo ------------- autonumber
Name -------------- Text
Age ---------- Number
Interset ------------ (Text)
//In Interset Properties through lookup tag I have
Display Control -------ListBox
Row Source Type --------- Value List
Row Source ---------------- "Swimming","Football","Cricket",hockey"
When I made form I got all the List Box Items. For single Selection it has worked. But If I want Multiple selection. I changed the property List Box property Multi Select from "None" to Simple. Now It worked with Multiple Selection.But If one first record I select Swimming, Football.On second record it would be blank. And select my self. But the previous one is saved on all the next records.If two selction on first next all same selction with 2.
If three then three.
I want Individual selection. It must be saved.According to corresponding record.
Facillitate in this regard is much appreciated.
hey all,
I'm using this code on a command button to delete single entries in a listbox... and it works fine
Private Sub DeleteMovie_Click()
CurrentDb.Execute "Delete from " & _
"tblMovies " & _
"where Title = """ & Me.lstList & """", dbFailOnError
Me.Requery
Me.lstList.Requery
Me.lstList = ""
End Sub
However, I want to try to select and delete multiple items in the list box. So I changed the property to allow multiple selections and now the button doesn't do anything when I click it. Ideally, I'd like the button to provide a "are you sure (yes or no)" prompt. Anyone know how to get this working? thanks a bunch
Using Access 2003.
I will have a ListBox on the form with “Multi Select” set to either simple or extended. I have a collection of documents which must be recorded in a database. Some documents may have only one author, but could have more. Same with the recipient or copied-to.
Ideally it would be nice to have the ListBox on the left, selected one or more from the list and then pass them to one of the three fields by a command button, sort of like:
cmdAuthorAuthor1
LISTBOXcmdRecipientsRecipient1; Recipient2
cmdCopiedTo Copy1; Copy2; Copy3
I would like to have all of the names selected from the ListBox as a string, but fully understand the problems associated with normalization. Other posts have suggested subforms. So, the question is how to select from the ListBox and then pass the possible multiple selections to discrete fields on a subform that would display, say three fields and which would get away from the normalization issues:
cmdAuthor [Author1] [ ] [ ]
LISTBOXcmdRecipients [Recipient1] [Recipient2] [ ]
cmdCopiedTo [Copy1] [Copy2] [Copy3]
The secondary issue will be that there will be subsequent names which are not found until actually in the process of document review which will create a need to update the ListBox, which I know is not akin to a ComboBox NotInList function.
If there are any thoughts or coding out there which will help, it’d be appreciated.
Lawguy
thank you in advance for all your BIG help. :)
I have 3 tables - SMaster, SI_map, ILookup
I need to create a form to Add/Update into SMaster and SI_map tables, which has one-to-many relationship, that's why I use a list box to show the values from SI_map.
in SMaster [ Sid, other fields ]
in SI_map [ primary key, Sid, ILookupid ]
in ILookup [ ILookupid, IName ]
questions:
1. How to get the multi-selected values from the list box?
2. insert these multiple records into SI_map table at the same time with SMaster (if I use the same form to populate all these fields)
3. how to populate the records into form for user to see and update the values?
Any suggestion is appreciated, it is very flexible to change any format such as SMaster and SI_map can be separate forms, as long as it works.
Thank you.
I'm using Access 2010, though am also familiar with Access 2007. I have a listbox populated with a query (concatenated last and first names with a bound ID field that's invisible). One of my users asked if it would be possible to search the listbox by more than the first letter of the name. As it stands now, if you type Smith, the focus would go to the first name starting with the letter "H", rather than Smith.
I've spent a lot of time researching this and come to the conclusion that this functionality does not exist within a listbox. However, I've discovered, a popular suggestion is to change the listbox to a combobox, which has this functionality. Since my listbox is multiselect, that would not work for me.
I'm trying to setup a listbox so that multiple items may be selected and removed at once. The Listbox Multi Select property is currently set to "Extended" and I have the following code on the onclick event of a command button:
Code:
Private Sub Command12_Click()
Dim i As Integer
For i = List10.ListCount - 1 To 0 Step -1
[Code]....
I have tested selecting 4 or so records on the list box and then pushing the remove button but it seems that the only record that is removed is the selected record that is furthest down on the listbox. The other selected records become unselected and must be reselected in order to continue removing records.
In my form I have the listFunctions list box set to Multi Select "Extended" in the following code contains a line to execute a query based on the selected items in a listbox. but for some reason instead of only changing the selected items it is changing all items in the listbox. I stepped through the code and it is looping the correct number of times based on the amount selected but is still changing all.
eg.if I select 3 items from the list, it loops through the execute 3 times.but the total 6 items will change.
Code:
Private Sub cmdEdit_Click()
Dim varItm As Variant
Dim sSQL As String
Dim ssSQL As String
[code]...
I have a form called "Record Call" when a user can input the calls that they have made or are scheduled. This form is based on the table "Call Records". I have created a new table called "CallAttendees" and added a listbox to my form for users to select who attended/participated in the call.
My code loops through the selections and writes these selections to the "CallAttendees" table. In this table i have an auto #, CallRecord, and Attendee fields. My code is supposed to write the "ID" field from the "Call Record" table to the "CallAttendees" table so that i can create the relationship between the two tables. However, this field is coming up blank since my form isn't generating the auto # until the record is closed.The tables are stored in a SQL server. I also tried saving the record prior to running my code.
I have a form with a listbox in which users should be able to move the items up and down. The listbox has 4 columns and multiple selection is enabled.
For a NON multiselect box I have it working, and also for a multiple selection box but in that case it works only for one row at a time.
For a NON multiselect listbox:
Code:
cmdDown_Click()
Dim i As Integer
Dim t1 As String, t2 As String, t3 As String, t4 As String
i = selectie.ListIndex
t1 = Nz(selectie.Column(0, i))
t2 = Nz(selectie.Column(1, i))
[Code] ....
You can select an item and then press "Down" as many times as you want to put the items as "down" in the list as you want it to be.
Multiselect listbox
This code also works for a multipleselection listbox when one item is selected, however, after you press "down" the item is still selected (highlighted) as the code reselects is (last line) BUT the value of selectie.listindex apparently is set to "-1".
Pressing "Down" again generates an error (i = -1). I can evade the error by adding "if selectie.listindex <=0 then exit sub", but that doens't fix the problem that the only way I can manage to reset the listindex to the new "position" of the item is to click on it again and THEN press "Down".
To fix this and be able to press "down" multiple times listindex should be set to the new value.
Adding a "me.selectie.listindex = i -1" doens't work (error), it seems like this value is readonly.
I can't find a way to "simulate" a mousepressed selection and really set the listindex.
The other problem is of course that this code doens't support moving multiple items at once: listindex points to the last selected item, but only one.
So, I tried another piece of code to move multiple items, not using listindex (since that resets to -1), but I run into another problem
Code:
Private Sub cmdDown_Click()
Dim var As Variant
Dim i As Integer
Dim n As Integer
Dim t1 As String, t2 As String, t3 As String, t4 As String
n = Me.selectie.ItemsSelected.Count
[Code] ....
The problem with this is: I can select multiple items and press "Down", but the problem now is that the selection is lost as soon as the code removes the first item, and the 2nd loop skips the if selected(i) = true (nothing is selected anymore).
The me.selectie.selected(i+1) = true doens't work since that would only reselect the first item after moving it.
The code "forgets" which items were selected and moves only one item...So I guess I need to put the indexnumbers in memory while moving the items.
I have been searching a lot, but can only find VB-solutions. In VB it's a lot simpeler using f.e. the .list property of a listbox, which is not available in MSAccess
The solution I'm thinking about is:
- set an array with the numbers of selected items
- put indexnumbers of the selected items in the array (f.e. 3 and 4)
- move items based on the indexnumers in the array
- when moving an item update the indexnumber in the array (3>4, 4>5)
- after moving all items reset the selection based on the array
It occurred to me then if I'm going to use an array anyway, I might as well load all items in an array, do the "resorting" and the reload the items in the list from the array. Might be more straightforward?
Btw...It seems VB has a simple solution to moving items: listbox.list(i) = listbox.list(i+1) or something like that moves an item. Even Excel seems to have this property but not MS Access!
How do I remove multiple selected items from listbox.
Noticed it is a table/query listbox, not value list.
Remove selected.zip
I have a form where I am trying to use 4 combo boxes(nomenclature,BPN,vendor, and reference) to filter a list box containing part numbers. The way I have it set up right now is in the listbox it is searching for each field and then in the criteria section i have [Forms]![myform]![respectedFieldsCombo].
This works when selections are made from the combo boxes but when one is blank (not being used to filter) then I assume it passes null for that value and the listbox doesn't return anything. I have tried to make it so the listbox ignores null values but im still having this problem.
For example: If i only have a selection for the vendor combo box then i want the list box to show all respective part numbers for that vendor, where nomenclature or any of the other fields are irrelevant. I also want to be able to stack these filters upon every new combo box selection.