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!

Run time error 91

Status
Not open for further replies.
Nov 6, 2002
89
CH
Hi

I have the following code to try to limit records in a subform:

Private sub Form_AfterUpdate()
Dim rs As Dao.Recordset
set rs = Me.RecordsetClone
'limit records to a max of 14
Me.Allow Additions = rs. RecordCount < 14
End Sub

Unfortunately, there is a run time error 91 (object variable or with-block variable not defined) on the line
Me.AllowAdditions = rs.RecordCount < 14

Do you know what is wrong in the code`?

Thanks.

Stefan
 
You probably need to restructure a little. I believe allowadditions is a boolean field.

If rs.RecordCount < 14 then
Me.AllowAdditions = True
End if
 
Well the test is for a boolean value, so that's not a problem (cmmrfrds: Access reads that line as
Me.Allow Additions = (rs. RecordCount < 14
evaluating the part in the parens to a boolean value first and then setting the property to that value).

But there are a couple of problems here...

One is that you're using hte wrong event...you should use the AfterInsert event. But you'll also want to do this test in the Open event, so I'd just put it in a separate function and call that function from both of those events.

The other one is that you're not testing for cases where there are no records. My guess is that you're getting this error when you open the form when there are no forms. You'll want to include some test like
if rs.eof and rs.bof then
yadda.aloowadditions = true
else
Me.Allow Additions = rs. RecordCount < 14
end if

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Thanks you both for your comments.

Unfortunately, MS Access still creates the same error when entering a new record (altough there are only 9 records in the subform).

Could it be that the references are wrongly set? If yes, how should they be set?

Is there any other code to get this problem solved ?

Thanks and regards,

Stefan
 
Hey jeremy

if rs.eof and rs.bof then
yadda.aloowadditions = true
else
Me.Allow Additions = rs. RecordCount < 14
end if

can u explain this code a little for me please? :)
I'm more than likely reading it wrong ... if the recordset is eof and bof??

Transcend
 
in case stefan does not come back -
rs.eof and rs.bof occurs when there are no records in the set. This is good programming practise method.

rollie@bwsys.net
 
Hmm. I didn't notice the spaces in here. They're most likely typos in your post, not your code, but if they're in your code, it won't work:
Me.Allow Additions = rs. RecordCount < 14
should be
Me.AllowAdditions = rs.RecordCount < 14

Let us know if the spaces were in your code

J =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
No the spaces were not in my code (sorry for the confusion).

I assume that my references are not correctly set.

What references do I need so that the code should work and what is their priority order?

Thanks,

Stefan
 
Hmm. OK, set a reference to microsoft dao, the highest version you've got in your list. That should do it. Sorry. You pointed that out earlier and I didn't get what you were talking about. So much for trying to answer questions early in the morning!

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Hmm. OK, set a reference to microsoft dao, the highest version you've got in your list. That should do it. Sorry. You pointed that out earlier and I didn't get what you were talking about. So much for trying to answer questions early in the morning!

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top