UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> populating a form...    
 
   
drmojo418
post Mar 24 2005, 11:44 AM
Post #1

UtterAccess Guru
Posts: 566
From: missouri, usa



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
Go to the top of the page
 
+
Mitchell
post Mar 24 2005, 11:50 AM
Post #2

UtterAccess VIP
Posts: 3,275
From: England



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
Go to the top of the page
 
+
drmojo418
post Mar 24 2005, 01:34 PM
Post #3

UtterAccess Guru
Posts: 566
From: missouri, usa



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
Go to the top of the page
 
+
Mitchell
post Mar 24 2005, 02:37 PM
Post #4

UtterAccess VIP
Posts: 3,275
From: England



Are we talking about multiple selections in the list box, or just one?
Go to the top of the page
 
+
drmojo418
post Mar 24 2005, 02:48 PM
Post #5

UtterAccess Guru
Posts: 566
From: missouri, usa



multiple and on the very rare occassion one at a time.
Go to the top of the page
 
+
Mitchell
post Mar 24 2005, 03:12 PM
Post #6

UtterAccess VIP
Posts: 3,275
From: England



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
Go to the top of the page
 
+
drmojo418
post Mar 24 2005, 03:42 PM
Post #7

UtterAccess Guru
Posts: 566
From: missouri, usa



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
Go to the top of the page
 
+
Mitchell
post Mar 24 2005, 03:44 PM
Post #8

UtterAccess VIP
Posts: 3,275
From: England



Does the form you are opening also have the AgentID field as part of the Record Source?
Go to the top of the page
 
+
drmojo418
post Mar 24 2005, 03:45 PM
Post #9

UtterAccess Guru
Posts: 566
From: missouri, usa



yes, but on the form it is coming from a query instead of a table. will that make the diffrence?

chad
Go to the top of the page
 
+
Mitchell
post Mar 24 2005, 03:48 PM
Post #10

UtterAccess VIP
Posts: 3,275
From: England



No shouldn't make any difference. What DataType is the AgentID field?
Go to the top of the page
 
+
drmojo418
post Mar 24 2005, 03:52 PM
Post #11

UtterAccess Guru
Posts: 566
From: missouri, usa



text
Go to the top of the page
 
+
Mitchell
post Mar 24 2005, 03:55 PM
Post #12

UtterAccess VIP
Posts: 3,275
From: England



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
Go to the top of the page
 
+
drmojo418
post Mar 24 2005, 04:53 PM
Post #13

UtterAccess Guru
Posts: 566
From: missouri, usa



thanks that worked great.

chad
Go to the top of the page
 
+
Mitchell
post Mar 24 2005, 09:20 PM
Post #14

UtterAccess VIP
Posts: 3,275
From: England



No problem (IMG:http://www.utteraccess.com/forum/style_emoticons/default/frown.gif)
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 25th May 2013 - 05:52 AM