Results 1 to 6 of 6

Thread: item cannot be found in the collection corresponding

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    110

    item cannot be found in the collection corresponding

    Code:
    Private Sub cmdPrint_Click()
    Set Record = New ADODB.Recordset
    Record.Open "SELECT orno,qty,rate,tamount,Edate,cname,cmob,city,gst,pack,ck (SELECT COUNT(*) FROM Ord C2 WHERE C2.prodname <= C.prodname) AS Sno FROM Ord C where orno = '" & txtOrdNo.Text & "' ORDER BY prodname ", Connect, 1, 3
        If Record.RecordCount > 0 Then
    
            With RptOrder
                Set RptOrder.DataSource = Record
                .Sections("Section4").Controls("Label18").Caption = Record!gst
                .Sections("Section4").Controls("Label15").Caption = Record!CName
                .Sections("Section4").Controls("Label17").Caption = Record!city
                .Sections("Section4").Controls("Label19").Caption = Record!cmob
                .Sections("Section4").Controls("Label20").Caption = Record!orno
                .Sections("Section4").Controls("Label12").Caption = Recor***** Error in this Line
                    .Show 1
                Set Record = Nothing
             End With
            Exit Sub
        End If
    
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Jan 2018
    Posts
    268

    Re: item cannot be found in the collection corresponding

    Your example seems to have cut off the portion of the code that is erroring...
    There are three "collections" in your example, the Sections collection, the Controls collection, and the Recordset Fields collection.
    90% chance that you're specifying a field/column name that doesn't exist. Otherwise Label12 doesn't exist.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    110

    Re: item cannot be found in the collection corresponding

    Code:
    Private Sub cmdPrint_Click()
    Set Record = New ADODB.Recordset
    Record.Open ("SELECT " _
                              & "(SELECT COUNT(*) FROM [Ord] WHERE [OrderNo] like'" & lblOrderNo.Caption & "'" _
                              & "AND [ID] <= [T].[ID]) AS [SerNo], " _
                              & "* FROM [Orders ] [T] WHERE [OrderNo] like'" & lblOrderNo.Caption & "'"), Connect, 1, 3
            If Record.RecordCount > 0 Then
            With RptOrder
                Set RptOrder.DataSource = Record
                    .Sections("Section4").Controls("Label15").Caption = Record!CustomerName
                    .Sections("Section4").Controls("Label17").Caption = Record!city
                    .Sections("Section4").Controls("Label18").Caption = Record!tin
                    .Sections("Section4").Controls("Label19").Caption = Record!ContactNo
                    .Sections("Section4").Controls("Label20").Caption = Record!OrderNo
                    .Sections("Section4").Controls("Label21").Caption = Record!Trans  ------->it is exist in database also
                    .Show 1
                Set Record = Nothing
            End With
            Call Orders
            Exit Sub
        End If
    
    End Sub

  4. #4
    Addicted Member
    Join Date
    May 2016
    Location
    China
    Posts
    197

    Re: item cannot be found in the collection corresponding

    In fact, in addition to returning a record number, your query should not return anything else...
    Because the field you want to use is not included in the select。
    QQ: 289778005

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: item cannot be found in the collection corresponding

    That last one does not even look like a valid sql statement.

    How about you show us the line that was cut off in the first post?

    At any rate though it should be as was said earlier either label12 does not exist or more likely the field name on that line is incorrect but since you cut it off in your post can only guess.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: item cannot be found in the collection corresponding

    in the first post example trans is not a selected field in the sql
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width