Results 1 to 1 of 1

Run time error '3265': item cannot be found in the collection corresponding to the reques

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Run time error '3265': item cannot be found in the collection corresponding to the reques

    this file works as it is used to download data from the database in starting row 3

    i blank sheet have given headers then i download the data

    but it doesnt recoginse its header columns while running update(Saving) macro code instead it shows an error

    how can i make this code to recognise the columns header name while updating or save the data in the database

    this are header columns
    BMS_ID level(1/2/3) item num Original Mfg Name Original Mfg Part # Original_Supplier Name Original_Supplier Part # Original_Description Mfg Name MFR Part No SUPPLIER_NAME SUPPLIER_PART NO Noun MODIFIER Noun Modifier



    please let me know

    i have attached my woorkbook

    and this is my Download data code

    Dim cnt As ADODB.Connection
        Dim rst1 As ADODB.Recordset, rst2 As ADODB.Recordset
        Dim stDB As String, stSQL1 As String, stSQL2 As String
        Dim strConn As String
        Dim wbBook As Workbook
        Dim Sheet1 As Worksheet
        Dim i
        Dim lnField As Long, lnCount As Long
        Dim dataStr As String
         'Instantiate the ADO-objects.
         
         
        Set cnt = New ADODB.Connection
        Set rst1 = New ADODB.Recordset
        Set rst2 = New ADODB.Recordset
    
        Set wbBook = ThisWorkbook
        Set Sheet1 = wbBook.Worksheets(1)
    
         'Path to the database.
        stDB = "mysql32"
    
         'Create the connectionstring.
        strConn = "Driver=MySQL ODBC 5.2 Unicode Driver;" _
        & "Data Source=" & stDB & ";"
        
         ' BMS.Show
    
         'The 1st raw SQL-statement to be executed.
          'stSQL1 = "SELECT * FROM tblbatch_headers where idBatch " & batchID & "order by col_seq asc"
    
         'The 2nd raw SQL-statement to be executed.
         stSQL2 = "SELECT * FROM  " & BMS.TextBox1 & "  where FQR_User_Code='" & Environ("userName") & "' and line_status in('QP')"    '
         'Clear the worksheet.
    '     Sheet1.Range("A3:FA3").CurrentRegion.Clear
           
                With cnt
            .Open (strConn)   'Open the connection.
            .CursorLocation = adUseClient 'Necessary to disconnect the recordset.
        End With
    
         With rst1
    '       .Open stSQL1, cnt    'Create the recordset.
           Set .ActiveConnection = Nothing 'Disconnect the recordset.
         End With
    
        With rst2
            .Open stSQL2, cnt 'Create the recordset.
            Set .ActiveConnection = Nothing 'Disconnect the recordset.
        End With
    
        With Sheet1
    '        .Cells(2, 1).CopyFromRecordset rst1 'Copy the 1st recordset.
         For i = 2 To rst2.Fields.Count
                '.Cells(2, i).Value = rst2.Fields(i - 1).Name
             Next i
            .Cells(3, 1).CopyFromRecordset rst2 'Copy the 2nd recordset.
           Unload BMS
       End With
    
         'Release objects from the memory.
    '    rst1.Close
       '  Set rst1 = Nothing
        rst2.Close
        Set rst2 = Nothing
        cnt.Close
        Set cnt = Nothing
    
        With Sheets("Sheet1")
    .Unprotect "password"
            .Cells.Locked = False
            .Columns(2).Locked = True
            .Columns(3).Locked = True
            .Columns(4).Locked = True
            .Columns(5).Locked = True
            .Columns(6).Locked = True
            .Protect "password", AllowFiltering:=True
    
    End With
    update code

    Dim dbconn As New ADODB.Connection
    Dim stDB, strConn
    
    Dim totColumns, totRows, i, j, BMS_id, UpdateprBatchName, List, Msg
    Dim prBatchName, prTableQry, inTableQry, prTableQry1, dbQry
    Dim rs As New ADODB.Recordset
    
    With Sheets("Sheet1")
    .Unprotect "password"
            .Cells.Locked = True
            .Columns(2).Locked = True
    End With
    
     'Path to the database.
        stDB = "mysql32"
    
         'Create the connectionstring.
        strConn = "Driver=MySQL ODBC 5.2 Unicode Driver;" _
        & "Data Source=" & stDB & ";"
        
        
         
    Sheet1.Activate
    'prBatchName = "tblprod_agr_007"
    
    totColumns = ActiveSheet.Cells(2, 16).CurrentRegion.Columns.Count
    totRows = ActiveSheet.Cells(3, 1).CurrentRegion.Rows.Count
    
     'prBatchName = ActiveSheet.Cells(3, totColumns + 1).Values
    dbconn.Open strConn
    rs.CursorLocation = adUseServer
    rs.Open "select * from " & update.txt1, dbconn, adOpenStatic, adLockOptimistic
        For j = 3 To totRows + 1
           BMS_id = ActiveSheet.Cells(j, 1)
            rs.Find "BMS_ID='" & BMS_id & "'"
            
            For i = 16 To totColumns
           rs(ActiveSheet.Cells(2, i).Value) = ActiveSheet.Cells(j, i)
            Next
            rs.update
              Next
    rs.Close
    dbconn.Close
           
    MsgBox "Data updated sucessfully"
    Attached Files Attached Files
    Last edited by baig123; 12-08-2014 at 07:48 AM. Reason: paragraph

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run-time error '-2147024809 (80070057)' Item with specified name wasn't found
    By tom_6030 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-08-2014, 10:24 PM
  2. [SOLVED] run time error '3265'; item cannot be found in the collection corresponding to the regues
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-08-2014, 03:29 AM
  3. Replies: 2
    Last Post: 05-13-2014, 07:07 AM
  4. [SOLVED] Run-time error 3265, but fields do exist!
    By jik_ff in forum Access Tables & Databases
    Replies: 2
    Last Post: 01-14-2014, 12:23 AM
  5. [SOLVED] Run Time Error 3265 - Item not found in this collection
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-23-2013, 07:19 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1