Without knowing your db structure I'll do my best. My code is listed in the
BeforeUpdate event for the form but you can place where it is needed. Below,
it is listed in the Exit event of the list box.
Private Sub ListBoxName_Exit(Cancel As Integer)
Dim strList as String
Dim intLen as Integer
Dim varSelectedRecord as Variant
If Me.ListBoxName.ItemsSelected.Count > 0 Then
For Each varSelectedRecord In ListBoxName.ItemsSelected
strList = strList + ListBoxName.Column(1, varSelectedRecord) & ","
Next varSelectedRecord
intLen = Len(strList)
[FieldName] = Left(strList, intLen - 1)
strList = ""
End If
End Sub
ListBoxName = The name of your list box
FieldName = The name of the field where you want to store the information
This code builds a string, seperated by commas. For example, say the list
box contains the words one, two, three, four, five and only one, two are
selected. "one, two" (without quotes) would be stored in the field.
dlewis1002 said:
xRoachx,
I am not very good with code. Can you give me step by step instruction on
how to build a field and where to put the code you sent.
Thanks.
xRoachx said:
You need to loop through the selections, build a string, then add this to the
field. The following is a code snipit from a module so you need to replace
the list box name and field name with your own:
If Me.lstProviderType.ItemsSelected.Count > 0 Then
For Each strSelectedRecord In lstProviderType.ItemsSelected
strList = strList + lstProviderType.Column(1, strSelectedRecord)
& ","
Next strSelectedRecord
intLen = Len(strList)
[ProviderType] = Left(strList, intLen - 1)
strList = ""
End If
lstProviderType = List Box
:
I have created a form that contains listboxs. I am unable to select the
information in the listbox and have it populate the appropriate field in my
table. If this takes some sort of marco, I am unable to write the correct
code to do this. Any information about this or even the code to do this
would be helpful.
Thanks