Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Shawn is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    7

    424 Object Required runtime error generated within vba module

    Hello. I am hoping that a second set of eyes can help me to resolve an error I am encountering.



    I have attached two files; the first is the code of the module I executing, and the second is the interpreted SQL statement that is failing.

    Line 79 within the module is where the failure is occurring, with error message 424 Object Required.

    For the life of me, I cannot see which object may be required.

    As background for this, the code defines two recordsets against the same data source.

    The first record set is being used to identify records I wish to process, and the second recordset, within the loop, is extracting the data I need to evaluate in order to update the records in the first recordset.

    This module is not accessing any fields from any other objects (like forms or reports), but is "simply" accessing data from the table within the database.

    Thank you in advance.

    Shawn
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,920
    Why don't you just post this info as text within question?

    I don't want to count 79 lines - which line is number 79?

    Are [Emp ID] and Locn text fields?

    Strongly advise not to use spaces nor punctuation/special characters in naming convention.
    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.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Run each in turn to see what if anything is produced?

    FWIW Line 79 in Notepad++ is
    Code:
    Set EEStartandEndRS = CATSDailydb.OpenRecordset(SQLString, dbOpenDynaset)
    I would have used CurrentDB() or set a db object to CurrentDB() ?

    Edit: OK, I see you have further up and have used that in a previous SQL statement, so it is not that.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Shawn is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    7
    Thank you June 7. I thought it might be easier to see the line numbers in a separate rather than in the body of the question.

    Yes, [Empl ID] and Locn are text fields.

    Line 79 is: Set EEStartandEndRS = CATSDailydb.OpenRecordset(SQLString, dbOpenDynaset)

    Execution is failing on the first pass through the data, and the second attachment contains the data, formatted as I would expect, at the point of failure.

    Shawn



  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Do you actually need all those left brackets with the Criteria each time?
    Code:
    SELECT [tbl - CATS Activity].[Empl Id],
           [tbl - CATS Activity].[Locn],
           [tbl - CATS Activity].[Balance Date],
           Min([tbl - CATS Activity].[Start Time Adj]) as Min_Start_Time_Adj,
           Max([tbl - CATS Activity].[End Time Adj]) As Max_End_Time_Adj
      FROM [tbl - CATS Activity]
     WHERE ((([tbl - CATS Activity].[Empl Id])="1000981") and
            (([tbl - CATS Activity].[Locn])="4025") and
            (([tbl - CATS Activity].[Balance Date])=#6/22/2021#) and
            (([tbl - CATS Activity].[Worked/Lost])="Work/Pay"))
    GROUP BY [tbl - CATS Activity].[Empl Id], [tbl - CATS Activity].[Locn], [tbl - CATS Activity].[Balance Date];
    Have you run each in turn to see if they work?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,920
    I opened text file and did not see line numbers. Forgot, should have used Notepad++, still better to post code in question and identify the line triggering error - don't make work for readers any more than necessary.

    The extra parentheses aren't really necessary but Access throws them in anyway and I expect OP copy/pasted from query SQLView.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  7. #7
    Shawn is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    7
    That volume of brackets is a technique I picked up from the SQL generated by the Query by Example query builder feature of Access.

    They are not all needed. Originally, I did not have the brackets around the variable names (ie. i originally had [tbl - CATS Activity].[Emp Id]="1000981") and when that failed, I added the additional brackets, thinking that if the query builder added them, then maybe I should too.

    It might be presuming too much, but it seems to me by that question, you are not seeing anything that immediately jumps out as being incorrect. It might be odd, but not incorrect.

    I am wondering if in all of this, there might be some sort of contention between the recordsets with the manner in which I attempt to open them. Does that make sense?

  8. #8
    Shawn is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    7
    Thank you June7.

    Your suspicion is correct. That is what I did after the initial failure.

    I will see about reducing the volume of data in the tables before compressing and attaching.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,920
    ( ) are parentheses
    [ ] are brackets
    { } are braces

    ( ) are used to structure SQL statements, Access is really picky about them when joining multiple tables, they are important when mixing AND and OR operators, otherwise, Access throws in more than are needed in WHERE clause

    [ ] are needed for object names that use spaces, punctuation/special characters, or are reserved words
    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.

  10. #10
    Shawn is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    7
    Attached is a zipped version of the database.

    I have restricted the data to instances for 4 different Empl Id values.

    There are a number of linked tables/datasets in this that I expect are not included in the compression process, but none of them are used in the module I am attempting to execute.

    I expect to be making use of them when my runtime error is resolved.

    The single module Assess_EE_Trady_and_HE contains the source code for the function.

    Thank you,

    Shawn
    Attached Files Attached Files

  11. #11
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,411
    The original 424 error is because the database is never dimmed:
    Code:
    Function mdl_Assess_EE_Tardy_and_HE()
    On Error GoTo Function_error
    
    
    DoCmd.Hourglass True
    
    
    Dim CATSActivityRS As Recordset
    Dim EEStartandEndRS As Recordset
    '''''
    Dim CatsDailydb As DAO.Database
    '''''
    Dim Start_Time As String
    Dim End_Time As String
    
    
    Dim TardyCount As Long
    Dim HECount As Long
    Dim ErrCount As Long

  12. #12
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also change
    Code:
    Dim CATSActivityRS As DAO.Recordset
    Dim EEStartandEndRS As DAO.Recordset
    ---------------------------------------------------

    You have declared
    Code:
    Dim ErrorFlag As Boolean
    but in code you have
    Code:
       If Error_Flag = False Then
    note the underscore...

    --------------------------------------------------------------

    Code:
          If EEStartandEndRS![Max_End_Time_Adj] < CATSActivityRSRS![End Time] Then
    Too many RS???

    ---------------------------------------------------------------

    Do you have
    Code:
    Option Compare Database
    Option Explicit
    as the top two lines of EVERY Module? If not, you should!!

    ----------------------------------------------------------------

    Delete this line
    Code:
        CATSDailydb.Close
    You did not open the dB, so you do not close it.


    Code:
        CATSActivityRS.Close
        EEStartandEndRS.Close
        CATSDailydb.Close  'delete
    
        Set CATSActivityRS = Nothing   'ADD
        Set EEStartandEndRS = Nothing   'ADD
        Set CATSDailydb.Close = Nothing   'ADD
    
    
    DoCmd.Hourglass False
        MsgBox Err.Description
        Exit Function

  13. #13
    Shawn is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    7
    Well that was silly, wasn't it.

    Thank you for catching that.

    Shawn

  14. #14
    Shawn is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    7
    Thank you for the suggestions.

    And thank you to all who took time to review this, and offer suggestions.

    All will be put in my back pocket.

    Shawn

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Quote Originally Posted by davegri View Post
    The original 424 error is because the database is never dimmed:
    Code:
    Function mdl_Assess_EE_Tardy_and_HE()
    On Error GoTo Function_error
    
    
    DoCmd.Hourglass True
    
    
    Dim CATSActivityRS As Recordset
    Dim EEStartandEndRS As Recordset
    '''''
    Dim CatsDailydb As DAO.Database
    '''''
    Dim Start_Time As String
    Dim End_Time As String
    
    
    Dim TardyCount As Long
    Dim HECount As Long
    Dim ErrCount As Long
    So why did it not fail on line 36?
    Set CATSDailydb = CurrentDb()
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error Object required: Please help
    By lccrews in forum Programming
    Replies: 1
    Last Post: 06-14-2018, 10:59 AM
  2. Runtime 424 error... Object required.
    By sanderson in forum Programming
    Replies: 8
    Last Post: 08-09-2015, 08:10 PM
  3. Runtime Error 424 Object Required
    By Maltheo2005 in forum Programming
    Replies: 9
    Last Post: 06-13-2013, 04:52 PM
  4. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  5. Object Required Error.
    By Robeen in forum Forms
    Replies: 1
    Last Post: 03-28-2011, 10:30 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