Avatar of mlcktmguy
mlcktmguy
Flag for United States of America asked on

run time error 7951 "You entered an expression that has an invalid reference to the recordset clone property

I am getting run time error 7951 "You entered an expression that has an invalid reference to the recordset clone property., on this statement

gBogusLong1 = Me.RecordsetClone.RecordCount  whic is part of this code block

Private Sub Form_Current()
  
If Me.NewRecord Then        'should never be a new record on this form
Else
    gBogusLong1 = Me.RecordsetClone.RecordCount
    '
    If Me.RecordsetClone.RecordCount > 0 Then  'only do this if records exists.
        'clone
        ' Set up globals for the current tax record, different id's are on it.
        '
        gCurrGRBID = Nz(Me.GRBID, 0)
        '
    End If
    '
End If
'

End Sub

Open in new window


I copied this code block from another Access 2013 application, where it works with no issues. .

The purpose of the code is to save off the ID of the first record on the continuous screen after a requery but only if there is a record.  If the returned recordset has no records I want to bypass the setting of the ID.

Any ides why I am getting this error in this application but not the other.  Or, Is there a better way to accomplish what I am trying to do?


If I try to type the command in using the intellisense there definitely in no 'Recordcount' option available.
Microsoft Access

Avatar of undefined
Last Comment
mlcktmguy

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Gustav Brock

Try to be more explicit. At least it may pin down the source of the error:


Private Sub Form_Current()

    Dim Records As DAO.Recordset

    If Not Me.NewRecord Then
        Set Records = Me.RecordsetClone
        gBogusLong1 = Records.RecordCount
       
        If gBogusLong1 > 0 Then  'only do this if records exists.
            'clone
            ' Set up globals for the current tax record, different id's are on it.
            '
            gCurrGRBID = Nz(Me.GRBID, 0)
            '
        End If
       
    End If

End Sub

Open in new window

Fabrice Lambert

The RecordsetClone return a reference to a new recordset each time it is called.

Try saving the reference first:

Dim Clone As DAO.Recordset
Set Clone = Me.RecordsetClone
    '// other code.

Open in new window

mlcktmguy

ASKER
Thanks Ryan.  Pure oversight on my part.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes