Runtime Error '91'

brow1726

Registered User.
Local time
Today, 13:12
Joined
Dec 12, 2012
Messages
17
I am trying to pull multiple fields from a ListBox to create individual records. I keep getting the runtime Error. Here is my code:

Code:
Private Sub Command30_Click()
    Dim strSQL      As String
    Dim db          As DAO.Database
    Dim rs          As DAO.Recordset
    Dim ctl         As Control
    Dim varItem     As Variant
    
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("TimeOffTracking", dbOpenDynaset, dbAppendOnly)
    
    If Me.EmployeeList.ItemsSelected.Count = 0 Then
        MsgBox "Must select at least 1 employee"
        Exit Sub
    End If
    
    Setctl = Me.EmployeeList
    For Each varItem In ctl.ItemsSelected
        rs.AddNew
        rs!Name = ctl.ItemData(varItem)
        rs!DateOff = Me.DateOff
        rs!TypeofAbsence = Me.TypeofAbsence
        rs!TimeStart = Me.TimeStart
        rs!TimeEnd = Me.TimeEnd
        rs!HoursUsed = Me.HoursUsed
        rs!Occurence = Me.Occurence
        rs!Comments = Me.Comments
        rs.Update
    Next varItem
    
ErrorHandler:
    Select Case Err
        Case Else
            MsgBox Err.Description
            DoCmd.Hourglass False
        End Select
        
End Sub

Any Help would be great!! Thanks!
 
There's a space missing in this line...

Setctl = Me.EmployeeList

...should be

Set ctl = Me.EmployeeList
 
I am trying to pull multiple fields from a ListBox to create individual records. I keep getting the runtime Error. Here is my code:

Code:
Private Sub Command30_Click()
    Dim strSQL      As String
    Dim db          As DAO.Database
    Dim rs          As DAO.Recordset
    Dim ctl         As Control
    Dim varItem     As Variant
 
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("TimeOffTracking", dbOpenDynaset, dbAppendOnly)
 
    If Me.EmployeeList.ItemsSelected.Count = 0 Then
        MsgBox "Must select at least 1 employee"
        Exit Sub
    End If
 
    Setctl = Me.EmployeeList
    For Each varItem In ctl.ItemsSelected
        rs.AddNew
        [B][COLOR=red]rs!Name = ctl.ItemData(varItem)[/COLOR][/B]
        rs!DateOff = Me.DateOff
        rs!TypeofAbsence = Me.TypeofAbsence
        rs!TimeStart = Me.TimeStart
        rs!TimeEnd = Me.TimeEnd
        rs!HoursUsed = Me.HoursUsed
        rs!Occurence = Me.Occurence
        rs!Comments = Me.Comments
        rs.Update
    Next varItem
 
ErrorHandler:
    Select Case Err
        Case Else
            MsgBox Err.Description
            DoCmd.Hourglass False
        End Select
 
End Sub

Any Help would be great!! Thanks!

The line highlighted in red is where I am getting my error. Not sure why?:banghead: It's Runtime error 3265
 
Last edited:
I agree with Josh

Setctl = Me.EmployeeList should be

Set ctl = Me.EmployeeList

The Set command to assign the Object has not been recognized because it has a syntax error (space needed)
 

Users who are viewing this thread

Back
Top Bottom