Combo Box, List Box and Error 424

D

David Wetmore

This code raises error 424. How do I copy a row from a two-column combo box
into a two-column list box.

The combobox, cbox gets its rows from a query



Option Compare Database
Option Explicit

Private Sub cbox_Click()
lbox.Column(0) = cbox.Column(0)
lbox.Column(1) = cbox.Column(1)
End Sub
'
 
D

Douglas J. Steele

You could use the AddItem method:

Private Sub cbox_Click()
Me.lbox.AddItem cbox.Column(0) & ";" & cbox.Column(1)
End Sub

That assumes that the listbox has its RowSourceType set to Value List.
 
D

David Wetmore

This is what I tried. No error messages, but both columns in the list box are Null

Private Sub AddToSearch(cboDescrip As ComboBox, lstTarget1 As ListBox, lstTarget2 As ListBox)
Dim strAdd As String
strAdd = CStr(cboDescrip.Column(0)) & ";" & cboDescrip.Column(1)
If lstTarget1 = "" Then
lstTarget1.AddItem (strAdd)
Else
lstTarget2.AddItem Item:=strAdd
End If

End Sub
 
D

Douglas J. Steele

Also, did you remember to set the RowSourceType property of the list boxes
(and are they correctly set up to allow two values)?
 
D

David Wetmore

I found the problem, it was my brain or what passes for my brain.
Having read the Help documentation and corrected the column settings, things work perfectly.

I appreciate your help and apologize for my failure to think and study before I asked for 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