Error 3265 Item not found on this collection... (1 Viewer)

Villarreal68

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

I'm working with this code (same as earlier post), bur different error:

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")
    
   [COLOR=yellowgreen] Set ctl = Me.lstAfuera  'FIXED THANKS TO TONY[/COLOR] 

    'Make sure an item has been selected.
    If ctl.ItemsSelected.count = 0 Then
        MsgBox "Primero Selecciona un Territorio Para Aceptar."
        Exit Sub
    End If
    
        
        
        For Each varItem In ctl.ItemsSelected
            
            [COLOR=red]'rst!Position = ctl.Column(0, varItem)
            'rst.Seek "=", txtCheckOutID
            rst!Position = txtCheckOutID  This is my new issue...
[/COLOR]            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 know for sure that the data in column(0) is valid in the table. I even tried creating a textbox that reflects the data on column(0) to try and pick up the data from there (as you can see above), but I still get the following error:
" 3265 Item not found on this collection"

Any help is appreciated...
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 11:18
Joined
Jul 9, 2003
Messages
16,287
For Each varItem In ctl.ItemsSelected

I haven't worked on list boxes for quite a while, so I'm very rusty. Regarding this line:

For Each varItem In ctl.ItemsSelected

If this line was examining a form object it would read something like this:

For Each Control in Me.Controls
Meaning, for the collection of controls in the form (me.controls)
Look at each individual control.


If you apply the same logic to:

For Each varItem In ctl.ItemsSelected
Meaning, for each variant Item selected in the listbox, look at the variant.

Now I don't profess to understand list boxes, but I'm suspicious about this bit, and I suggest you ask someone who has a good knowledge of list boxes for an explanation or find some code somewhere that works and test it.
 

Villarreal68

Registered User.
Local time
Today, 03:18
Joined
Feb 15, 2007
Messages
133
Hello Tony,

Thanks for responding. I did do what you suggested. I found different code that worked fine.

I digged into a project that I had done about a year ago and it had code that worked for me.

Thanks for your response.
 

Villarreal68

Registered User.
Local time
Today, 03:18
Joined
Feb 15, 2007
Messages
133
Here's the code that worked for me for if someone is looking at a later date:

Code:
Dim varItem As Variant
Dim count As Integer
Dim found As Boolean
Dim rsCM As Object
       
For Each varItem In Me.lstAfuera.ItemsSelected
    count = count + 1
Next varItem
        If Me.lstAfuera.ItemsSelected.count = 0 Then
            MsgBox "Primero Selecciona un Territorio Para Aceptar."
            Exit Sub
        End If
        
        Set rsCM = CurrentDb.OpenRecordset("CheckOut")
        rsCM.MoveFirst
        
        For Each varItem In Me.lstAfuera.ItemsSelected
            found = False
            Do While Not rsCM.EOF And Not found
                If (rsCM.CheckOutID = CInt(txtCheckOutID)) Then
                    rsCM.Edit
                    rsCM!CheckInDate = Me.txtDate2
                    rsCM.Update
                DoCmd.GoToRecord , , acGoTo, txtTerrIn
                Me.TerrOut = False
                DoCmd.RunCommand acCmdSaveRecord
                
                found = True
            Else
                rsCM.MoveNext
            End If
        Loop
        rsCM.MoveFirst
        
        Next varItem
 

Users who are viewing this thread

Top Bottom