I've created a form containing a Multiselect Listbox. The selections of the Listbox should be written to a field within the current record being edited or added.
The code i'm using updates the proper field but always to the first record in the table. How can I update the field in the current record?
Here's the code:
Private Sub Command49_Click()
Dim strVal As String
Dim varItem As Variant
Dim ctl As Control
Dim rst As DAO.Recordset
Set ctl = Me.CategoryList
For Each varItem In ctl.ItemsSelected
strVal = strVal & ctl.ItemData(varItem) & "~~"
Next
strVal = Mid(strVal, 1, Len(strVal) - 2)
Set rst = CurrentDb.OpenRecordset("Links"
rst.Edit
rst!AltCategories = strVal
rst.Update
Set rst = Nothing
Set ctl = Nothing
End Sub
The code i'm using updates the proper field but always to the first record in the table. How can I update the field in the current record?
Here's the code:
Private Sub Command49_Click()
Dim strVal As String
Dim varItem As Variant
Dim ctl As Control
Dim rst As DAO.Recordset
Set ctl = Me.CategoryList
For Each varItem In ctl.ItemsSelected
strVal = strVal & ctl.ItemData(varItem) & "~~"
Next
strVal = Mid(strVal, 1, Len(strVal) - 2)
Set rst = CurrentDb.OpenRecordset("Links"
rst.Edit
rst!AltCategories = strVal
rst.Update
Set rst = Nothing
Set ctl = Nothing
End Sub