Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2004, 12:46 PM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default ListBox & Array

I've run into an issue that I am having a difficult time figuring out so any help will be appreciated.

Here's the story: I have two ListBoxes (lstMGR and lstTeam). I am trying to create a way that multiple teams can be assigned to a MGR by selecting the MGR and then selecting their assigned teams from the respective ListBoxes. I thought using an array would be a good way to store the team numbers (since each MGR can have up to 20 assigned to them) and used this code ...

Dim intRow As Integer
Dim strTeamNumber(0 To 99) As String

With Forms("frmLeadership").lstTeam
   For intRow = 0 To .ListCount
      If .Selected(intRow) = True Then
         strTeamNumber(intRow) = .Column(0)
         Debug.Print strTeamNumber(intRow)
      End If
   Next intRow
End With

This appears to work fine with one exception. If I choose team 001, 003, 005, and 007 for a MGR the array is loaded with the data from the last selected line in lstTeam (ie 005, 005, 005, 005 is the result).

My question is how do I get each selected row of data loaded into a separate array element?

Kenny Alligood
__________________
Kenny Alligood
 
Old February 15th, 2004, 12:57 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Kenny,
   Change the code .Column(0) to

   .itemdata(intRow)

   You could change it to use the Hidden ItemsSelected Collection

   Dim varItem as Variant
   Dim intCount as integer
   Dim strTeamNumber(0 TO 99) as String

   For Each varItem in Me.lstTeam
      strTemNumber(intCount) = me.lstTeam.ItemData(varItem)
      intCount = intCount+1
      debug.print strTeamNumber(intcount)
   Next

Hope this helps,
Mike
 
Old February 15th, 2004, 12:59 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

forgot one thing,

Change Me.lstTeam to Me.lstTeam.ItemsSelected

Mike
 
Old February 15th, 2004, 01:55 PM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx Mike -- I really appreciate your assistance! It appears that your plan worked but the value was not being assigned to the array element; so I'm going to change my plan. Here is how the code works...

Dim varItem As Variant
Dim strTeamNumber As String

With Forms("frmLeadership").lstTeam
   For Each varItem In .ItemsSelected
      strTeamNumber = .ItemData(varItem)
      Debug.Print strTeamNumber
   Next varItem
End With

I actually have this in a module therefore I can't us the Me keyword (in case you were wondering). What I plan to do now is use the value of strTeamNumber and .Update the rst from within the loop until all teams are assigned. I needed to .Update the rst anyway so this should work fine. Again, thanx for your help.

Kenny Alligood
 
Old February 15th, 2004, 02:10 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Kenny,
  Glad I could help. One final comment. You can use the Class object name in a standard module...this gives you the benefit of Intellisense.

   Instead of using Forms("frmLeadership").lstTeam

   use

   Form_frmLeadership.lstTeam

   Notice that when you type the period, you get the intellisence help.

Regards,
Mike
 
Old February 16th, 2004, 11:25 AM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another great tip -- thanx Mike!

Kenny Alligood





Similar Threads
Thread Thread Starter Forum Replies Last Post
add & Remove frm Listbox hotshot_21 ASP.NET 1.0 and 1.1 Basics 1 June 21st, 2007 05:26 PM
Add&Remove rows from DB using listbox martinhogan VB Databases Basics 3 September 11th, 2006 06:24 AM
ComboBox & ListBox usage venkikrao VB.NET 4 March 14th, 2006 07:50 AM
Parsing a Listbox Array jkilgo PHP How-To 2 December 21st, 2004 02:30 PM
Copy Items From An Array Into A ListBox? Adam166 VB.NET 2002/2003 Basics 2 November 22nd, 2003 11:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.