dbTalk Databases Forums  

Selected List Box Records into Variant

comp.databases.ms-access comp.databases.ms-access


Discuss Selected List Box Records into Variant in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Icarus
 
Posts: n/a

Default Selected List Box Records into Variant - 06-01-2011 , 01:53 PM






I have a combo box that based on what is selected populates a list
box. When the user creates a report, I create a variant that stores
the combo box value and the selected list box values.

However, when I look at the individual rows in the variant, I am
seeing values from the list box that were not selected.

How to I make sure that ONLY the rows that are selected (have been
clicked on and remain highlighted) are added to the variant?

My code:

Private Sub cmdCreateReport_Click()

Dim varitem As Variant
Dim varParameter1() As Variant
Dim ctl As Control
Dim intLstCount As Integer
Dim intCount As Integer

'add the parameter values into an array and run the function

'Parameter 1
Set ctl = Me.lstParameter1Values

intCount = 0

For intLstCount = 0 To Me.lstParameter1Values.ListCount

If Me.lstParameter1Values.Selected(intLstCount) = True
Then

varParameter1(intCount) =
Me.cboParameter1.Column(1) & ";" & ctl.Column(2, intCount)

intCount = intCount + 1

End If

Next

End Sub

Reply With Quote
  #2  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Selected List Box Records into Variant - 06-01-2011 , 06:23 PM






Icarus wrote:

Quote:
I have a combo box that based on what is selected populates a list
box. When the user creates a report, I create a variant that stores
the combo box value and the selected list box values.

However, when I look at the individual rows in the variant, I am
seeing values from the list box that were not selected.

How to I make sure that ONLY the rows that are selected (have been
clicked on and remain highlighted) are added to the variant?

My code:

Private Sub cmdCreateReport_Click()

Dim varitem As Variant
Dim varParameter1() As Variant
Dim ctl As Control
Dim intLstCount As Integer
Dim intCount As Integer

'add the parameter values into an array and run the function

'Parameter 1
Set ctl = Me.lstParameter1Values

intCount = 0

For intLstCount = 0 To Me.lstParameter1Values.ListCount

If Me.lstParameter1Values.Selected(intLstCount) = True
Then

varParameter1(intCount) =
Me.cboParameter1.Column(1) & ";" & ctl.Column(2, intCount)

intCount = intCount + 1

End If

Next

End Sub

Use the ItemsSelected collection. See the topic in VBA Help
for details and examples.

--
Marsh

Reply With Quote
  #3  
Old   
Icarus
 
Posts: n/a

Default Re: Selected List Box Records into Variant - 06-02-2011 , 10:58 AM



Thank you. The ItemsSelected helped.

My larger issue was the ctl.Column(2,intcount), which was pulling the
correct column from the list box, but the incorrect row.

Reply With Quote
  #4  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Selected List Box Records into Variant - 06-05-2011 , 11:00 AM



Icarus wrote:

Quote:
Thank you. The ItemsSelected helped.

My larger issue was the ctl.Column(2,intcount), which was pulling the
correct column from the list box, but the incorrect row.

Did you remember that the column/row numbers are zero based?
If the ColumnHeads [rp[erty is set to Yes. the first row is
the headers.

None of that should have any effect on your code if you use:

For Each varItm In Me.listbox.ItemsSelected
Me.listbox.Column(1,varItm)

But I can't tell if you are having trouble with the combo
box row or the list box row and you did not say anything
about the combo box.

--
Marsh

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.