Results 1 to 6 of 6
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Object required error 424

    In the segment of code below, I get an error Object Required on the "Set rsName" statement. Hopefully the code is clear enough to understand that the intent is to use the rsName object as the name of a DOA recordset name, of which there are four. I'm assuming there's something else required to make such a variable substitution?
    Bill




    Code:
    Private Sub MigrateHdgs()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim rsHeadings As DAO.Recordset
    Dim rsHd1 As DAO.Recordset
    Dim rsHd2 As DAO.Recordset
    Dim rsHD3 As DAO.Recordset
    Dim rsHD4 As DAO.Recordset
    Dim HDName As String
    Dim tblName As String
    Dim rsName As Object
    Dim ndx As Integer
    Dim JustSavedID As Integer
    
    Set rsHeadings = DBEngine(0)(0).OpenRecordset("QHeadings")    'Sorted by HD1 names
    
    strSQL = "SELECT * FROM tblHD1"
    Set rsHd1 = DBEngine(0)(0).OpenRecordset(strSQL)              'Should be empty
    strSQL = "SELECT * FROM tblHD2"
    Set rsHd2 = DBEngine(0)(0).OpenRecordset(strSQL)              'Should be empty
    strSQL = "SELECT * FROM tblHD3"
    Set rsHD3 = DBEngine(0)(0).OpenRecordset(strSQL)              'Should be empty
    strSQL = "SELECT * FROM tblHD4"
    Set rsHD4 = DBEngine(0)(0).OpenRecordset(strSQL)              'Should be empty
    
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Loop through the headings and populate the HD1, HD2, HD3 and HD4 tables as appropriate.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        rsHeadings.MoveFirst
        
        Do While Not rsHeadings.EOF
            arr = Split(rsHeadings!folder, "/")
            
            JustSavedID = 0
            
            For ndx = 0 To UBound(arr)
                HDName = arr(ndx)
                tblName = "tblHD" & Trim(Str(ndx + 1))
                Set rsName = "rsHD" & Trim(Str(ndx + 1))
                
                rsName.AddNew
                rsName!title = rsHeadings!Name
                rsName!Type = ndx + 1
                rsName!Fmt = ndx * 2
                rsName!MbrID = Null
                rsName!PtrURLs = Null
                rsName!PtrNxtHD = Null
                If JustSavedID > 0 Then _
                    rsName!MbrID = JustSavedID
                rsName.Update
                
                rsName.Bookmark = rsName.LastModified
                JustSavedID = rsName!HdID
                
            Next ndx
      
        rsHeadings.MoveNext
        Loop
    
    
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Close and release the Recordsets
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    rsHeadings.Close
    Set rsHeadings = Nothing
    
    rsHd1.Close
    Set rsHd1 = Nothing
    
    rsHd2.Close
    Set rsHd2 = Nothing
    
    rsHD3.Close
    Set rsHD3 = Nothing
    
    rsHD4.Close
    Set rsHD4 = Nothing
    
    End Sub

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Try Set rsName = eval("rsHD" & Trim(Str(ndx + 1))).OpenRecorset().

    Cheers,
    Vlad

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I created a string variable so I could see its value when runtime error occured. "Access cannot find rsHd1" is the error message.

    Code:
    (snip)
            For ndx = 0 To UBound(arr)
                HDName = arr(ndx)
                tblName = "tblHD" & Trim(Str(ndx + 1))
                strrsName = "rsHd" & Trim(Str(ndx + 1))
                Set rsName = Eval(strrsName).OpenRecorset()     <<<<<<<<<<<<<<<<< Error on this statement
                
                rsName.AddNew
                rsName!title = rsHeadings!Name
                rsName!Type = ndx + 1
                rsName!Fmt = ndx * 2
                rsName!MbrID = Null
                rsName!PtrURLs = Null
                rsName!PtrNxtHD = Null
                If JustSavedID > 0 Then _
                    rsName!MbrID = JustSavedID
                rsName.Update
                
                rsName.Bookmark = rsName.LastModified
                JustSavedID = rsName!HdID
                
            Next ndx
     
    (snip)

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Try this. It may be slow, maybe not. However it does work with a test DB. Let me know if you want the entire test DB and I'll post.
    Code:
    Public Sub MigrateHdgs()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim rsHeadings As DAO.Recordset
    Dim tblName As String
    Dim rsHDX As Recordset
    Dim ndx As Integer
    Dim JustSavedID As Integer
    Dim arr() As String
    Set rsHeadings = CurrentDb.OpenRecordset("QHeadings")    'Sorted by HD1 names
    
    
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Loop through the headings and populate the HD1, HD2, HD3 and HD4 tables as appropriate.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        rsHeadings.MoveFirst
        
        Do While Not rsHeadings.EOF
            arr = Split(rsHeadings!folder, "/")
            
            JustSavedID = 0
            
            For ndx = 0 To UBound(arr)
                tblName = "tblHD" & Trim(Str(ndx + 1))
                 'Debug.Print tblName
                Set rsHDX = CurrentDb.OpenRecordset(tblName)
                rsHDX.AddNew
                rsHDX!title = rsHeadings!Name
                rsHDX!Type = ndx + 1
                rsHDX!Fmt = ndx * 2
                rsHDX!MbrID = Null
                rsHDX!PtrURLs = Null
                rsHDX!PtrNxtHD = Null
                If JustSavedID > 0 Then _
                    rsHDX!MbrID = JustSavedID
                rsHDX.Update
                
                rsHDX.Bookmark = rsHDX.LastModified
                JustSavedID = rsHDX!HdID
                rsHDX.Close
            Next ndx
      
        rsHeadings.MoveNext
        Loop
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Close and release the Recordsets
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Set rsHeadings = Nothing
    
    
    Set rsHDX = Nothing
    End Sub
    Last edited by davegri; 06-21-2018 at 09:30 PM. Reason: tuneup

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I haven't studied your code but spotted a spelling error

    Set rsName = Eval(strrsName).OpenRecordset() <<<<<<<<<<<<<<<<< Error on this statement
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    This issue has to be dropped from further discussion. There was a much better way to structure the code in processing the data for the app. While I'd still like to know for future reference how to code a variable that can be set to the name of a DOA RecordSet, I unfortunately lost the original code that would have allowed me reasonable opportunity to experiment with the correction that Colin offered.......... sorry Colin.
    Bill
    (PS) And thanks to Vlad for the original suggestion

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. Object Required Error
    By sgp667 in forum Programming
    Replies: 1
    Last Post: 11-06-2012, 03:15 AM
  4. Error: Object Required
    By compooper in forum Programming
    Replies: 6
    Last Post: 06-22-2011, 07:52 AM
  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