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

No Current Record Error when closing Access form

I have a form that is giving me a "No current record" error when I close the form from a (New) record.

I have narrowed it down to this line of code on the on_Current event.

'If Me.Child124.Form.Recordset.RecordCount = 0 Then Me.PrimaryLinkBtn.Enabled = False Else Me.PrimaryLinkBtn.Enabled = True

Is there a simple way to work around this?

Thanks,
Dan
Microsoft AccessVisual Basic ClassicVBA

Avatar of undefined
Last Comment
filtrationproducts

8/22/2022 - Mon
Gustav Brock

You can use:

If Not Me.NewRecord Then
    If Me.Child124.Form.Recordset.RecordCount = 0 Then
        Me.PrimaryLinkBtn.Enabled = False
    Else
        Me.PrimaryLinkBtn.Enabled = True
    End If
End If

/gustav
filtrationproducts

ASKER
Gustav,

I tried that but unfortunately I still receive the "no current record" error when exiting. I read somewhere this had something to do with the "recordcount" command.

I am also confused as to why it errors when I close the form. I would think I would get the error right away when navigating to the new record.

But I know it has to be this line of code because when I comment it out/delete it I do not receive the errors anymore.

Dan
Gustav Brock

But if you really are on a new record, the code will be skipped.

So, I guess, something else is going on.

Or rewrite your code. There should be no reason to enable/disable controls when you close the form.

/gustav
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
filtrationproducts

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.
filtrationproducts

ASKER
It was bypassing the code when I was on a new record, I setup a msgbox to make sure. But for some mysterious reason I would still get the error message. I think it had something to do with using that "recordset.recordcount" command at any point when the form is open. Because once that line of code ran (when I navigated through records) then exited the form on a New record it would error.

Dan
Gustav Brock

OK. Great!

/gustav
filtrationproducts

ASKER
Found solution myself after posting question
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.