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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy Help. Runtime Error 3021: No current record.

Status
Not open for further replies.

nonturbo

IS-IT--Management
Aug 27, 2001
78
US
Simply put, I have a form where I've hidden the built-in nav buttons and made my own using the button wizard to make the following buttons: First, Previous, New, Next, and Last. All is well here.

I took it a step further and added this code to the form's OnCurrent event:
Code:
Dim recClone As Recordset
Set recClone = Me.RecordsetClone()
recClone.Bookmark = Me.Bookmark
recClone.MovePrevious
 BtnNavPrevious.Enabled = Not (recClone.BOF)
 BtnNavFirst.Enabled = Not (recClone.BOF)
recClone.Bookmark = Me.Bookmark
recClone.MoveNext
 BtnNavNext.Enabled = Not (recClone.EOF)
 BtnNavLast.Enabled = Not (recClone.EOF)
This essentially greys out the first/prev and last/next buttons on 1st and last record of recordset. This too, is all good. Works fine.

THE PROBLEM: When creating a new record, it crashes with Error 3021 No current record. Any suggestions? Thanks in advance!

 
So the code you pasted above is the code that craps-out on you? Well it could be because of the book mark thing you've got going there (I don't think you can set a bookmark when you're on an add new since there isn't a record there yet.) How about this:

If Me.NewRecord Then
'Do something
Else
'Do your thing as you normally would
End If


Kyle ::)
 
Nonturbo:

Put this at the beginning of the On_Current code:

If isnull(whatever your primary key field is) then
exit sub
End If

I use code similar to yours and always put this at the beginning for just the reason you indicate.

Hope this helps. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Kyle - Me.Newrecord! Eureka, we've found the answer. I never even knew Access supported that, but it looks to solve exactly my problem. Thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top