Unrecognised member of a recordset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Petrol
    New Member
    • Oct 2016
    • 248

    Unrecognised member of a recordset

    In Access 365 I have sub which opens a dynaset-type recordset based on a table, but it won't compile because it claims it "can't find" the fields in the records. It gives compile error 461, "Method or data member not found". Yet the fields are definitely there. Here is a simplified version of the sub:
    Code:
    Private Sub DeauthoriseSTC( )
    Dim rst As Recordset
    Set rst = CurrentDb.OpenRecordset("AccessAuthority", dbOpenDynaset)
    rst.MoveNext
    
    If rst.PersonID >1 Then
    DoEvents
    End If
    
    If rst.EventNum <> "" Then
    DoEvents
    End If
    
    If rst.Key = 0 Then
    DoEvents
    End If
    
    End Sub
    The AccessAuthority table is defined thus:

    Click image for larger version

Name:	image.png
Views:	241
Size:	97.5 KB
ID:	5641762

    If I comment out the first If block, the compile error shows on the second, and if I comment out the second, it shows on the third.
    However, despite what it says, the compiler is evidently finding the fields in the table, because if I type them in all lower case or all upper case, it changes them to the capitalisation in the table definition. For example, it changes "rst.person id" to "rst.Person ID", "rst.KEY" to "rst.Key" etc.

    Any suggestions gratefully received.
  • Petrol
    New Member
    • Oct 2016
    • 248

    #2
    I should have mentioned that when Access VBA gives the compile error, it highlights the field name (PersonID, EventNum, or Key, whichever it comes upon first) in the If statement.
    Also, when I changed the source of the recordset from the table to a query built on the table, containng the same fields amongst others, I still get the same compile error.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      Hi Petrol.

      I don't believe Fields are direct properties of a Recordset as you seem to assume. There is a Fields() Collection which allows you to refer to them in VBA, but as it's also a Default Collection you can refer to them using the bang (!) and that should work for you (IE. rst!EventNum, etc).

      Forms do create Control names as direct Properties so maybe that's what you're confusing it with.

      Comment

      • Petrol
        New Member
        • Oct 2016
        • 248

        #4
        Oh, a bang! How embarassing! How could I have missed that?
        Don't ever get old, Adrian. Remain perpetually Neo.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          While I may still have a few years left on my clock, my friend, I suspect avoiding old-age is a ship that's passed. Perhaps not quite there yet, but the direction is set so I'll enjoy the ride while I still may :-)

          PS. If you're living in Brisbane then why not come along to Kent Gorrell's next [link=https://accessusergroup s.org/access-express-australia/]Kent's Monthly Access Meet-Up[/link] meeting. He's also based there & has an online (Zoom) meeting every month. I'm usually along & it's good fun.

          Comment

          • Petrol
            New Member
            • Oct 2016
            • 248

            #6
            Thanks for that - I wasn't aware of that users grouop. It's not apparent from the linked-to website that there is a meeting in Friday 15th, but I'll have a look next week and see how we go.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              This Friday (14th) there's a San Fran one on, but for us it's actually early Saturday 15th. The link's :
              https://stanford.zoom.u s/rec/share/YSW_hrrSkGkUh-i_0wbaf2gaMRoxz QU0CY52u3lUNOCB YagztXCCvPR_sEE 00NQ0.g0GYvRN-5xUUoAbD?startT ime=17395794700 00
              Passcode: .M9mm.vR

              This is a little different from the usual details so sharing those too in case you need them :
              Meeting ID: 929 2609 8111
              Password: 038332

              The timing is 09:15 for you I believe - 00:15 for me - only just into the Saturday.

              Comment

              Working...