Listbox question

R

Raj

I have a list box on my main form that shows all entries for the current
user. I have set the OnDblClik Event to allow the user to delete entries.
When the user wants to delete the record at the EOF they get and Runtime
Error '3021 No current record. How can I get rid of having this happen when
the last record is deleted?
Thanks…
 
M

Marvin

Perhaps you have code that is trying to delete the record and then move to
the next record? If so, it may help to check whether you are at EOF before
executing ".movenext".

Marvin
 
R

Raj

Marvin,
I am using DoCmd.RunCommand (acCmdDeleteRecord) could this be the problem.
I am teaching myself access and not really sure how alot of thing work. Is
there a better way of deleting a record in a listbox
 
M

Marvin

Raj,

I believe this will work for you. I got it from Dev Ashish & Andy Baron's
site (http://www.mvps.org/access/forms/frm0021.htm).

To call the subroutine from within the form, you can use: fDelCurrentRec Me

The subroutine is:

'************** Code Start *************
Function fDelCurrentRec(ByRef frmSomeForm As Form) As Boolean
On Error GoTo Err_Section

With frmSomeForm
If .NewRecord Then
.Undo
fDelCurrentRec = True
GoTo Exit_Section
End If
End With

With frmSomeForm.RecordsetClone
.Bookmark = frmSomeForm.Bookmark
.Delete
frmSomeForm.Requery
End With
fDelCurrentRec = True
Exit_Section:
Exit Function

Err_Section:
fDelCurrentRec = False
Resume Exit_Section
End Function
'************** Code End *************

I believe fDelCurrentRec will avoid the error message because it works with
the RecordsetClone and requeries the record source.

Marvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top