ADOX Error 3265- "Item cannot be found..."

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charli
    New Member
    • Nov 2008
    • 23

    ADOX Error 3265- "Item cannot be found..."

    Error 3265, "Item cannot be found in the collection corresponding to the requested name or ordinal"

    code programatically opens a query using ADOX and changed the sql

    Code:
    Dim cat As New ADOX.Catalog
    Dim cmd As New ADODB.Command
    cat.ActiveConnection = CurrentProject.Connection
      
    Set cmd = cat.Procedures("qryLostCostCodes").Command 'opens existing query to edit
    cmd.CommandText = whr 'this should be your sql SELECT string
    Set cat.Procedures("qryLostCostCodes").Command = cmd 'save query
    cat.Views.Refresh
      
    Set cat = Nothing
    Set cmd = Nothing
    debug says the error is on the line:
    5. Set cmd = cat.Procedures( "qryLostCostCod es").Command

    so I was thinking maybe it couldn't find the query to open, but then if you alter it create a new query instead you get the error "Query already exists" (and I can see it exists)

    the SQL is:
    Code:
    SELECT [costcode], [name]
    FROM Site
    WHERE costcode NOT IN ('B', 'A9000', 'I9000', 'I4000', 'I4300', 'I4200')
    and costcode and name defintely exist... I even had this running at one point!

    Any Ideas?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by charli
    Error 3265, "Item cannot be found in the collection corresponding to the requested name or ordinal"

    code programatically opens a query using ADOX and changed the sql

    Code:
    Dim cat As New ADOX.Catalog
    Dim cmd As New ADODB.Command
    cat.ActiveConnection = CurrentProject.Connection
      
    Set cmd = cat.Procedures("qryLostCostCodes").Command 'opens existing query to edit
    cmd.CommandText = whr 'this should be your sql SELECT string
    Set cat.Procedures("qryLostCostCodes").Command = cmd 'save query
    cat.Views.Refresh
      
    Set cat = Nothing
    Set cmd = Nothing
    debug says the error is on the line:
    5. Set cmd = cat.Procedures( "qryLostCostCod es").Command

    so I was thinking maybe it couldn't find the query to open, but then if you alter it create a new query instead you get the error "Query already exists" (and I can see it exists)

    the SQL is:
    SELECT [costcode], [name] FROM Site WHERE costcode NOT IN ('B', 'A9000', 'I9000', 'I4000', 'I4300', 'I4200')
    and costcode and name defintely exist... I even had this running at one point!

    Any Ideas?
    Why not save yourself several lines of code as well as the External Reference:
    Code:
    Dim qdf As DAO.QueryDef
    
    Set qdf = CurrentDb.QueryDefs("qryLostCostCodes")
    qdf.SQL = "Select * From Yada, Yada, Yada...;"

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32634

      #3
      Looking through the Object Browser (F2) it seems that the Command property is a variant.

      It may be worth checking that cat.Procedures( "qryLostCostCod es").Command is an object of type ADODB.Command. I suspect there is a possibility of this being Null.

      Unfortunately I don't have anything I can check this on so it will need to be you doing the checking.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by charli
        Error 3265, "Item cannot be found in the collection corresponding to the requested name or ordinal"

        code programatically opens a query using ADOX and changed the sql

        Code:
        Dim cat As New ADOX.Catalog
        Dim cmd As New ADODB.Command
        cat.ActiveConnection = CurrentProject.Connection
          
        Set cmd = cat.Procedures("qryLostCostCodes").Command 'opens existing query to edit
        cmd.CommandText = whr 'this should be your sql SELECT string
        Set cat.Procedures("qryLostCostCodes").Command = cmd 'save query
        cat.Views.Refresh
          
        Set cat = Nothing
        Set cmd = Nothing
        debug says the error is on the line:
        5. Set cmd = cat.Procedures( "qryLostCostCod es").Command

        so I was thinking maybe it couldn't find the query to open, but then if you alter it create a new query instead you get the error "Query already exists" (and I can see it exists)

        the SQL is:
        Code:
        SELECT [costcode], [name]
        FROM Site
        WHERE costcode NOT IN ('B', 'A9000', 'I9000', 'I4000', 'I4300', 'I4200')
        and costcode and name defintely exist... I even had this running at one point!

        Any Ideas?
        Assuming you didn't like the Shortcut in Post #2, try this on for size, a slight change in syntax:
        Code:
        Dim cat As New ADOX.Catalog
        Dim cmd As New ADODB.Command
        
        cat.ActiveConnection = CurrentProject.Connection
        
        Set cmd = cat.Views("qryLostCostCodes").Command
        cmd.CommandText = "<Yada, Yada, Yada>;"
        
        Set cat.Views("qryLostCostCodes").Command = cmd 
        cat.Views.Refresh
          
        Set cat = Nothing
        Set cmd = Nothing

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32634

          #5
          ADezii,

          As your code is fundamentally the same up to the point where the OP reported the error (if I haven't misread somewhere) - is there any reason to assume this code will behave differently?

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by NeoPa
            ADezii,

            As your code is fundamentally the same up to the point where the OP reported the error (if I haven't misread somewhere) - is there any reason to assume this code will behave differently?
            1. Original Post Code Segment:
              Code:
              Set cmd = cat.Procedures("qryLostCostCodes").Command 
              cmd.CommandText = whr
              Set cat.Procedures("qryLostCostCodes").Command = cmd
            2. My revised Code Segment:
              Code:
              Set cmd = cat.Views("qryLostCostCodes").Command 
              cmd.CommandText = whr
              Set cat.Views("qryLostCostCodes").Command = cmd
            3. Original Code will fail at the Assignment of the cmd Object Variable, namely:
              Code:
              Set cmd = cat.Procedures("qryLostCostCodes").Command
            4. The revised Code will not fail at this Line when modified:
              Code:
              Set cmd = cat.Views("qryLostCostCodes").Command

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32634

              #7
              Ah. My bad. Thanks for the explanation.

              So you use .Views() where the original code used .Procedures. Nice :)

              Comment

              • charli
                New Member
                • Nov 2008
                • 23

                #8
                Both answers work beautifully! I have no real problem with using DAO, but thank for explaining why the original version didn't work!

                Charli

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Originally posted by charli
                  Both answers work beautifully! I have no real problem with using DAO, but thank for explaining why the original version didn't work!

                  Charli
                  Glad it all worked out for you, charli.

                  Comment

                  Working...