Link to home
Start Free TrialLog in
Avatar of filtrationproducts
filtrationproductsFlag 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
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

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
Avatar of 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
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
ASKER CERTIFIED SOLUTION
Avatar of filtrationproducts
filtrationproducts
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
OK. Great!

/gustav
Found solution myself after posting question