Skip Bisconer
Who Me?
- Local time
- Today, 11:59
- Joined
- Jan 22, 2008
- Messages
- 285
I have a multiselect listbox with the below code that errors out to "Method or data member not found" the error point stops at "rs.Position = ctl.ItemData(varItem)". I have attached the form and a screenshot of the table referenced. It has to be some little thing I am not seeing. Please advise.
This form has fields that carry over from another form but updates a different table.
This form has fields that carry over from another form but updates a different table.
Code:
Private Sub Command24_Click()
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ctl As Control
Dim varItem As Variant
'On Error GoTo ErrorHandler
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblTrainingRequirementsByAllPositions", dbOpenDynaset, dbAppendOnly)
'make sure a selection has been made
If Me.Position.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 position"
Exit Sub
End If
'add selected value(s) to table
Set ctl = Me.Position
For Each varItem In ctl.ItemsSelected
rs.Position = ctl.ItemData(varItem)
rs.AddNew
rs!CWSPolicy = Me.CWSPolicy
rs!Title = Me.Title
rs!Intv = Me.Intv
rs.Update
Next varItem
DoCmd.Close
ExitHandler:
Set rs = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
Select Case Err
Case Else
MsgBox Err.Description
DoCmd.Hourglass False
Resume ExitHandler
End Select
End Sub