VBA Code Problem with combo boxes on a form

brentos2004

Registered User.
Local time
Today, 22:53
Joined
Nov 30, 2005
Messages
11
Im using the following vba Code to try and populate a text box with multiple line based on selections from a list box.

Private Sub Precautions_AfterUpdate()
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant

Set ctl = Me.Precautions

For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then

Criteria = ctl.ItemData(Itm)
Else
Criteria = Criteria & "," & ctl.ItemData(Itm)
End If
Next Itm
Me.description = Criteria

End Sub

Its working to the extent that it adds the options that are selected from the list box but I actually want it to put the 2nd column of the list box which is hidden into the text box. How do i edit this code to add column 2 rather than column 1 when an option is clicked?

Any help would be appreciated

Ive attached the database (sorry its very simple) Open form tester to see what i mean.
 

Attachments

Hi,

Try the column property;

Code:
If Len(Criteria) = 0 Then
      
         Criteria = ctl.Column(1, Itm)
         
Else
         Criteria = Criteria & vbCrLf & ctl.Column(1, Itm)
         
End If
   Next Itm


HTH

TS
 
Last edited:
Thankyou very much that works great. Its appreciated
 

Users who are viewing this thread

Back
Top Bottom