Add more rows to a 3 column list box

G

Guest

Using Office 2003 and Windows XP;

Two 3-column listboxes on a form, arranged side-by-side. The left-side box
is populated using a record source. No problem.

I would like the user to be able to double-click on a record listed in the
left-side box and have it appear in the right-side list box. The following
code works for the first record. After that, it replaces the one record with
the next one clicked. How can I alter this code to add additional items?

Me.lbxReferencedNames.RowSourceType = "Value List"
Me.lbxReferencedNames.ColumnCount = 3
Me.lbxReferencedNames.RowSource = sNameID & ";" & sName & ";" & sBirthDate
 
C

Carl Rapson

XP said:
Using Office 2003 and Windows XP;

Two 3-column listboxes on a form, arranged side-by-side. The left-side box
is populated using a record source. No problem.

I would like the user to be able to double-click on a record listed in the
left-side box and have it appear in the right-side list box. The following
code works for the first record. After that, it replaces the one record
with
the next one clicked. How can I alter this code to add additional items?

Me.lbxReferencedNames.RowSourceType = "Value List"
Me.lbxReferencedNames.ColumnCount = 3
Me.lbxReferencedNames.RowSource = sNameID & ";" & sName & ";" & sBirthDate

Use ".AddItem" instead of re-defining the RowSource each time:

Me.lbxReferencedNames.AddItem sNameID & ";" & sName & ";" & sBirthDate


Carl Rapson
 
S

Stuart McCall

XP said:
Using Office 2003 and Windows XP;

Two 3-column listboxes on a form, arranged side-by-side. The left-side box
is populated using a record source. No problem.

I would like the user to be able to double-click on a record listed in the
left-side box and have it appear in the right-side list box. The following
code works for the first record. After that, it replaces the one record
with
the next one clicked. How can I alter this code to add additional items?

Me.lbxReferencedNames.RowSourceType = "Value List"
Me.lbxReferencedNames.ColumnCount = 3
Me.lbxReferencedNames.RowSource = sNameID & ";" & sName & ";" & sBirthDate

Me.lbxReferencedNames.AddItem sNameID & ";" & sName & ";" & sBirthDate

What the AddItem method does is the equivalent of:

With Me.lbxReferencedNames
.RowSource = .RowSource & sNameID & ";" & sName & ";" & sBirthDate
End With

but AddItem will be a bit quicker because it uses internal code to
concatenate the values in the RowSource.
 
G

Guest

Thanks, that works great; I was actually trying to make it more difficult
than it was...

Just one more request: how do you completely clear a multi-column listbox
using VBA? Is there a chance you could post generic example code?

Thanks again for the help!
 
G

Guest

Nevermind; I see I can blank the RowSource...

XP said:
Thanks, that works great; I was actually trying to make it more difficult
than it was...

Just one more request: how do you completely clear a multi-column listbox
using VBA? Is there a chance you could post generic example code?

Thanks again for the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top