borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Read multiple files in a folder and count number of occurance of a word!)Next Topic (AutoClose() vs DocClose(), FileClose(), FileExit(), et al.) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Is there a way to read individual column data from a VBA listbox? Solved Topic
Poster Message
ba1959nh
Level: Scholar

Registered: 10-05-2006
Posts: 39

icon Is there a way to read individual column data from a VBA listbox?

I am using VBA in Access 2003.

I have a listbox on an Access Form.

This listbox is populated using a SQL Query and that works fiine.

The SQL Query stores 4 text fields in the listbox (addr, city, state and zip).

Now I am hoping that I can read each column of data and store it in 4 separate textbox controls.

I have tried the following, but the results of the assignment to the textboxes are always Null.

Private Sub CheckWorkAddr()

Dim strSQL As String
Dim intSupporterID As Integer

intSupporterID = Me.comboSupporters

strSQL = "SELECT Supporters.SupporterID, Supporters.Addr, Supporters.City, Supporters.State, Supporters.Zip FROM Supporters WHERE Supporters.SupporterID = " & intSupporterID

Me.lstWorkAddr = Null
Me.lstWorkAddr.RowSource = strSQL

txtAddr = Me.lstWorkAddr.ItemData(1)
txtCity = Me.lstWorkAddr.ItemData(2)
txtState = Me.lstWorkAddr.ItemData(3)
txtZip = Me.lstWorkAddr.ItemData(4)

End Sub

I was hoping to NOT have to perform individual db reads to get each of these values.

Any idea how to do this?


I appreciate any assistance.
- Bill

26-05-2006 at 12:50 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: Is there a way to read individual column data from a VBA listbox?

Hi,
You use the column property on the listbox. As in:
txtAddr = Me.lstWorkAddr.Column(1)

You can also specify which row to read too...
txtAddr = Me.lstWorkAddr.Column(1,2)

...would give you column 1 of row 2

Hope this helps,
Kieron



____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

27-05-2006 at 09:27 AM
View Profile Send Email to User Show All Posts | Quote Reply
ba1959nh
Level: Scholar

Registered: 10-05-2006
Posts: 39
icon Re: Is there a way to read individual column data from a VBA listbox?

Yes - that was it.
Thanks.

27-05-2006 at 06:36 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Is there a way to read individual column data from a VBA listbox? Solved Topic
Previous Topic (Read multiple files in a folder and count number of occurance of a word!)Next Topic (AutoClose() vs DocClose(), FileClose(), FileExit(), et al.) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder