needhelplol
Programmer
i have found a way of using a multi-select box, entering data into a database, and then pulling it back out into a from,
hope this helps someone
this was a little dvd collection database i was creating for my self, "genre" is a field in "dvd" table, list8 is the list box on the form, the form_current is being used as it kept the previous selected items as you moved between records.
hope everything else is understandable
hope this helps someone
Code:
Private Sub Form_Current()
'Deselect old values
Dim varItem As Variant
For Each varItem In List8.ItemsSelected
List8.Selected(varItem) = False
Next
'Call Update List
Update_List
End Sub
Private Sub Update_List()
''retive data stored in database
'S = Genre Values in table as array
Dim S As Variant
'Loop counter
Dim X As Variant
'lower and upper array values
Dim l As Variant
Dim u As Variant
'Genre_values
Dim Values As String
'check to see if database already has values stored in it
gen = IsNull(Genre.Value)
If gen = True Then
Else
'if yes, then spilt values
Values = Genre.Value
S = Split(Values)
l = LBound(S)
u = UBound(S)
'select correct items on the form
For X = 0 To List8.ListCount - 1
For y = 0 To UBound(S)
If (Val(List8.ItemData(X)) = Val(S(y))) Then
List8.Selected(X) = True
End If
Next y
Next X
End If
End Sub
Sub List8_AfterUpdate()
'' add data to database
Dim strQuery As String
Dim varItm As Variant
Dim test As Variant
Dim First As Integer
Dim Last As Integer
Dim i As Integer
Dim j As Integer
Dim Temp As Variant
Dim List As String
For Each varItm In List8.ItemsSelected
strQuery = strQuery + List8.ItemData(varItm) + " "
Next varItm
strQuery = Trim(strQuery)
'sort listings
qry = Split(strQuery, " ")
First = LBound(qry)
Last = UBound(qry)
For i = 0 To Last - 1
For j = i + 1 To Last
If qry(i) > qry(j) Then
Temp = qry(j)
test(j) = qry(i)
test(i) = Temp
End If
Next j
Next i
For i = 0 To UBound(qry)
List = List & " " & qry(i)
Next
List = Trim(List)
Genre.Value = List
'call update_list to check data has been enterd correctly
Update_List
End Sub
this was a little dvd collection database i was creating for my self, "genre" is a field in "dvd" table, list8 is the list box on the form, the form_current is being used as it kept the previous selected items as you moved between records.
hope everything else is understandable