Error 91 Object variable not set...

Villarreal68

Registered User.
Local time
Today, 02:48
Joined
Feb 15, 2007
Messages
133
Hello Everyone,

I'm having an issue with this code:

Code:
Dim rst           As DAO.Recordset
Dim db            As DAO.Database
Dim ctl           As Control
Dim varItem       As Variant
    On Error GoTo Err_btnAceptar
    
        Set db = CurrentDb()
        Set rst = CurrentDb.OpenRecordset("CheckOut")
    
    
    'Make sure an item has been selected.
    If ctl.ItemsSelected.count = 0 Then
        MsgBox "Primero Selecciona un Territorio Para Aceptar."
        Exit Sub
    End If
    
        Set ctl = Me.lstAfuera
        
        For Each varItem In ctl.ItemsSelected
            rst!Position = ctl.Column(0, varItem) 
            rst.Edit
            rst!CheckInDate = Me.txtDate2
            rst.Update
            
            DoCmd.GoToRecord , , acGoTo, txtTerrIn
            Me.TerrOut = False
            DoCmd.RunCommand acCmdSaveRecord
            
            MsgBox "Aceptado"
         Next varItem
Exit_btnAceptar:
    rst.Close
    Set rst = Nothing
    Set ctl = Nothing
    Me.lstAfuera.Requery
    Me.lstDisponibles.Requery
    
    
    Exit Sub

Err_btnAceptar:
    If Err.Number = 3314 Then
        MsgBox "Primero Asigna a un publicador."
    Exit Sub
    End If
    
    If Err.Number = 3421 Then
        MsgBox "Primero Asigna a un publicador."
    Exit Sub
    End If
    
    MsgBox Err.Number & Err.Description
    Resume Exit_btnAceptar

I'm not an expert with VB, but I'm trying.

All I want to do is to select the value on Column(0) of my varItem on the Listbox to find the exisitng record and do an update to a date field.

I been looking at this code for about 3 days now and I can't figure out what's missing or wrong. I've read lots of posts similar to my code and it just looks fine to me. But the ugly meesage:

"91 - Oblect variable or With block variable not set" keeps on popping up.

Any help would be greatly appreciated.
 
Which line does it error out on (comment out the error handler so you can click DEBUG and go to the offending line).
 
Hi Tony and Bob,

you mean I need to insert this line earlier on the code?:
Set ctl = Me.lstAfuera

I'll comment out the error handler...and try.

Thanks!
 
Last edited:
Tony Thanks!

Yes that fixed the issue!

Now it gives me a different error:
"3265 item not found on this Collection"

Off to figure that one now!

Thanks for your help!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom