Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error 91 on a recordcount statement

Status
Not open for further replies.

RandDUser

Technical User
Feb 24, 2005
65
US
In my form's OnCurrent event, I have the following code:

Me.Text43.Value = Me.Recordset.RecordCount

When the form opens, it give me the Runtime error 91: Object variable or with block variable not set

However, I have the same code in another form, and it runs fine.

Any thoughts?
 

Hmmm....

Have you tried

me.recordsetclone.recordcount

It counts a temporary copy of the table and should work.


Is the form bound to a recordset at the time this bit of code runs? you may find if it runs before binding you get this error.
 
when I try the recordsetclone, it gives me runtime error 7951 "You entered an expression that has an invalid reference to the recordsetclone property"

The form is unbound by the way, but the ultimate task I want to do is have this code:

Me.Text43.Value = [tables]![tbl_main].Recordset.RecordCount

I want the total number of records in a table to appear on the form. However, that code also produces the same runtime error 91, so I tried using the Me.Recordset.RecordCount to if the same error occured, and it does.
 
And what about the DCount function ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I just tried the DCount function:

Me.Text43.Value = DCount([FIELDNAME], "tbl_main")

and I get the Runtime error 2465, "Microsoft Access cannot find the field "|" referred to in your expression"

Here is the entire code:

Private Sub Form_Current()
Me.Text43.Value = DCount([FIELDNAME], "tbl_main")
End Sub

Am I writing the DCount formula incorrectly?

Thank you
 
Check out the DCount function in the help files, you will find it expects the fieldname you wish to count within double quotes. I think you can also call it without specifying fieldname, with for instance

[tt]me!text43.value = dcount("*", "tbl_main")[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top