drmojo418
Mar 24 2005, 11:44 AM
how would i go about populating a form with the records selected froma list box. what i have is a list box that shows all my agents id numbers and the left of that i have a button that will select agents by whole teams at a time. and to the right of the list box i have a button that opens the report/form so the supervisor can see what type of activity the agent had for a particular day. my problem comes when i click on the button to open the form i don't get any data in my form. so i guess how do i tell the report that is open to pull the agent id's from the list box and run the report based off the select agentid's that are in the list box.
thanks
chad
Mitchell
Mar 24 2005, 11:50 AM
I'm guessing you need to loop through the SelectedItems property of the list box, and build a string of criteria to use as a filter. I'm not sure how the SelectedItems property works in List boxes, but a search on the help system should yield some useful info.
HTH
drmojo418
Mar 24 2005, 01:34 PM
i have searched every where on that and am finding nothing. the way that i have it set up is on my list box i have it reading from qryAgentNames with it only showing column one which is WWID'S. To the left of the list box i have buttons set up for the supervisors to select only there team members and to the right of the list box i have a button that opens another form that is in Continuous Form. but when i click on the button it doesn't return any data for the team in which i have selected.
thanks
chad
Mitchell
Mar 24 2005, 02:37 PM
Are we talking about multiple selections in the list box, or just one?
drmojo418
Mar 24 2005, 02:48 PM
multiple and on the very rare occassion one at a time.
Mitchell
Mar 24 2005, 03:12 PM
Here is an example of what I mean:
CODE
Private Sub cmdForm_Click()
Dim strFilter As String, varItem As Variant
For Each varItem In lstData.ItemsSelected
If strFilter = "" Then
strFilter = "[TestID] = " & lstData.ItemData(varItem)
Else
strFilter = strFilter & " Or [TestID] = " & lstData.ItemData(varItem)
End If
Next varItem
DoCmd.OpenForm "frmShowData", WhereCondition:=strFilter
End Sub
I assume the button you have on the left, just changes what is displayed in the list box. The button on the right will open the form, showing the items selected in the list box. The Multi Select property of the list box must be set to either Simple or Extended. I have used TestID as the field name for my primary key so you should change this to whatever field is in the Bound Column of the list box that will determine which records are displayed on the form. The WhereCondition is where you tell what the next form's records are going to be by using the strFilter variable that was generated in the For Each .... loop.
HTH
drmojo418
Mar 24 2005, 03:42 PM
Every time i run the code i get boxes pop up boxes with the world wide id's in them. i have included pictures of the way it is layed out. and the of the pop up box.
here is the code i put in:
Private Sub RunReport_Form__Click()
Dim strFilter As String, varItem As Variant
For Each varItem In List10.ItemsSelected
If strFilter = "" Then
strFilter = "[AgentID] = " & List10.ItemData(varItem)
Else
strFilter = strFilter & " Or [AgentID] = " & List10.ItemData(varItem)
End If
Next varItem
DoCmd.OpenForm "Test_Form2", WhereCondition:=strFilter
End Sub
thanks
chad
Mitchell
Mar 24 2005, 03:44 PM
Does the form you are opening also have the AgentID field as part of the Record Source?
drmojo418
Mar 24 2005, 03:45 PM
yes, but on the form it is coming from a query instead of a table. will that make the diffrence?
chad
Mitchell
Mar 24 2005, 03:48 PM
No shouldn't make any difference. What DataType is the AgentID field?
drmojo418
Mar 24 2005, 03:52 PM
text
Mitchell
Mar 24 2005, 03:55 PM
Ahh...if the field is text, you need to make sure that you use single quotes around the values you are filtering for, otherwise access doesn't treat the values as strings, but numbers.
CODE
For Each varItem In List10.ItemsSelected
If strFilter = "" Then
strFilter = "[AgentID] = '" & List10.ItemData(varItem) & "'"
Else
strFilter = strFilter & " Or [AgentID] = '" & List10.ItemData(varItem) & "'"
End If
Next varItem
However, you shouldn't be filtering by a text field, but rather the Primary Key that belongs to the data you are looking for. AgentID should not be a primary key in a table
HTH
drmojo418
Mar 24 2005, 04:53 PM
thanks that worked great.
chad
Mitchell
Mar 24 2005, 09:20 PM
No problem
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.