Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple column Value List listboxes...?

Status
Not open for further replies.

bujin

MIS
Oct 2, 2000
144
GB
Are they possible?

I have a form where a trainee surname, forename, employer along with some other details are entered. When I click an "Add" button, I would like the details to be added to a multiple column listbox. This would be done through Visual Basic code. Since in Access Visual Basic there is no "lst.AddItem" method, I have created my own as follows:

Sub AddListItem(lst As Control, S As String)
With lst
If (.ControlType = acComboBox) Or (.ControlType = acListBox) Then
If .RowSourceType = "Value List" Then
If .ListCount > 0 Then
.RowSource = .RowSource & "; " & S
Else
.RowSource = .RowSource & S
End If
End If
End If
End With
End Sub

For example, to add "hello" to the lstPointless listbox, I call:

AddListItem lstPointless, "hello"

This then builds up the RowSource and adds the values to the list. However, it only works with single-column listboxes. I was wondering if multiple column value lists are possible and if so, how do I do them?

Thanks
 
Actually, scratch that! I've found the answer.
 
Glad you found your solution. Please post your answer here. It may help someone else later on...

Thanks. Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
Sure. The answer is simple enough. Each time I make a call to the AddListItem sub, it adds data into the next column, wrapping around to the next row once all columns are filled. So for example, if I want to add the following details:

ADAMS, Andrew (06/04/77)
BENSON, Bob (05/02/77)
CARTER, Carl (12/11/76)

to a three-column table (tblDetails), I just do the following:

AddListItem tblDetails, "ADAMS"
AddListItem tblDetails, "Andrew"
AddListItem tblDetails, "06/04/77"
AddListItem tblDetails, "BENSON"
AddListItem tblDetails, "Bob"
: : : : : : : : : : : : : : : : :
AddListItem tblDetails, "12/11/76"

This will work as long as tblDetails is set up to have three columns and its RecordSourceType property is set to "Value List".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top