Results 1 to 9 of 9
  1. #1
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64

    Item cannot be found in the collection corresponding to the requested name or ordinal

    Hello:



    And thanks for all the help this week. As I mentioned, it's been several years since I have done VBA, in favor of .NET applications. I think this question is hopefully easy??

    The title says it all, re, error 3265. It appears to be happening at string creation time, which really puzzles me.

    Code:
        sql = "SELECT * FROM tblocalApprovalLog " & _
              "WHERE empid = '" & rs.Fields("empid") & "' " & _
              "AND dayDate = '" & Forms!frmTimeCard.txtDate.Value & "' " & _
              "AND weekDate = '" & Forms!frmTimeCard.txtPeriodStart.Value & " - " & Forms!frmTimeCard.txtPeriodEnd.Value & "' "
    Here is the entirety of the sub...

    Code:
    Private Sub chkApprove_Click()
        Dim rs As adodb.recordset
        Set rs = New adodb.recordset
    
    
        Dim sql As String
        sql = "SELECT * FROM tblocalApprovalLog " & _
              "WHERE empid = '" & rs.Fields("empid") & "' " & _
              "AND dayDate = '" & Forms!frmTimeCard.txtDate.Value & "' " & _
              "AND weekDate = '" & Forms!frmTimeCard.txtPeriodStart.Value & " - " & Forms!frmTimeCard.txtPeriodEnd.Value & "' "
        
        Debug.Print ("sql: " & sql)
          
        rs.Open sql, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
        
        If Not rs.BOF Then
            rs.MoveFirst
            
            If Me.chkApproved = False Then
                rs.Fields("approved") = True
            
            End If
              
        End If
        
        rs.Close
        Set rs = Nothing
                   
    End Sub
    Again, much thanks for all the help!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you dont need the ampersand AND the continuation underscore

    just use 1 of them:

    Code:
    sql = "SELECT * FROM tblocalApprovalLog "  _
              "WHERE empid = '" & rs.Fields("empid") & "' " _
              "AND dayDate = '" & Forms!frmTimeCard.txtDate.Value & "' " _
              "AND weekDate = '" & Forms!frmTimeCard.txtPeriodStart.Value & " - " & Forms!frmTimeCard.txtPeriodEnd.Value & "' "

  3. #3
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    When I remove the &, the whole thing turns red! Is this my problem? Because it is how I have coded all the other sql statements...

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    if it doesnt like the underscores, you can use a concatinate...

    Code:
    sql = "SELECT * FROM tblocalApprovalLog " 
    sql = sql & "WHERE empid = '" & rs.Fields("empid") & "' " 
    sql = sql & "AND dayDate = '" & Forms!frmTimeCard.txtDate.Value & "' " 
    sql = sql & "AND weekDate = '" & Forms!frmTimeCard.txtPeriodStart.Value & " - " & Forms!frmTimeCard.txtPeriodEnd.Value & "' "

  5. #5
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    So here's the problem...

    This line refers to itself...

    Code:
        sql = sql & "WHERE empid = '" & rs.Fields("empid") & "' " & _
    The problem is, if I remove it everything happens on the first field. The goal is to have a recordset of 1 and change a second checkbox when the first one is selected. I do not know hoe wlse to isolate the data, as empid and the two dates must all be equal.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    one other note, if empid is a number (autonumber) field your string won't work you'll hve to remove the ' marks around it

    "WHERE empid = " & rs.Fields("empid") & " "

  7. #7
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    empid is a string

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The error is because of this
    Code:
    "WHERE empid = '" & rs.Fields("empid") & "' " & _
    The rs is not SET to anything at the time you use your SQL. You need to place another variable in there. Your WHERE clause does not make any sense.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    The & and _ are needed in the original code. The issue is as ItsMe states - this concatenation references an ADODB recordset (rs) that has not been opened. Need to pull empID from somewhere other than recordset.

    Also can't change value in recordset field without first setting the recordset to EditMode and then have to Update.

    An UPDATE action would be simpler.

    Much of this is shown in your other thread https://www.accessforums.net/program...set-54473.html.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Item Not Found In Collection For TableDefs
    By gammaman in forum Modules
    Replies: 2
    Last Post: 06-17-2015, 07:55 AM
  2. The requested member of the collection does not exist.
    By murfeezlaw in forum Programming
    Replies: 2
    Last Post: 07-12-2013, 07:24 AM
  3. Replies: 3
    Last Post: 11-16-2012, 10:15 AM
  4. Julian (ordinal) date one day off
    By gregu710 in forum Access
    Replies: 6
    Last Post: 02-02-2012, 06:21 PM
  5. Item not found
    By thart21 in forum Programming
    Replies: 7
    Last Post: 04-14-2010, 10:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums