troubleshooting Question

how to avoid getting the "You can't go to the specified record" error when deleting the first record.

Avatar of MurphyPH
MurphyPH asked on
Microsoft AccessVBA
22 Comments2 Solutions689 ViewsLast Modified:
I need to detect when I am at BOF and can't figure this out.  The r.BOF value is always false even when at record 1.

Private Sub cmdDeleteRecord_Click()
On Error GoTo Err_cmdDeleteRecord_Click
    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
 Dim r As DAO.Recordset
Set r = CurrentDb.OpenRecordset("SELECT * FROM Wetform")
'How to get the BOf to be true when at record 1.
If r.BOF Then
    DoCmd.GoToRecord , , acNext
    DoCmd.GoToRecord , , acPrevious
End If
    DoCmd.SetWarnings True
    Exit Sub
    MsgBox Err.Description
    Resume Exit_cmdDeleteRecord_Click
End Sub
Join our community to see this answer!
Unlock 2 Answers and 22 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros