Kayleigh
Member
- Local time
- Today, 16:53
- Joined
- Sep 24, 2020
- Messages
- 706
Hi, Trying to code a function which finds the record selected in listbox and sets fldDefault as True. Also resets existing fldDefault to False (if different from current selection).
Here is my code - not sure how to continue...
Here is my code - not sure how to continue...
Code:
Private Sub cmdDefault_Click()
Dim X As Integer
Dim i As Variant
Dim DBS As DAO.Database
Dim rst As DAO.Recordset
Dim td As DAO.TableDef
Set DBS = CurrentDb
Set td = DBS.TableDefs!jtblStaffRoles
Set rst = td.OpenRecordset(dbOpenDynaset)
For Each i In Me.lstSelectedPositions.ItemsSelected
rst.FindFirst "fldStaffPositionID = " & Me.lstSelectedPositions.ItemData(i) & " And fldStaffID = " & Me.fldStaffID
If Not rst.fldDefaultPosition = True Then
rst!fldDefaultPosition = True
End If
Debug.Print Me.lstSelectedPositions.ItemData(i)
On Error Resume Next
rst.Update
Next i
rst.Close
Set rst = Nothing
Set td = Nothing
Me.Refresh
Exit Sub
End Sub