We help IT Professionals succeed at work.
Get Started

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

MurphyPH
MurphyPH asked
on
688 Views
Last Modified: 2017-04-03
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
Else
    DoCmd.GoToRecord , , acPrevious
End If
    DoCmd.SetWarnings True
Exit_cmdDeleteRecord_Click:
    Exit Sub
Err_cmdDeleteRecord_Click:
    MsgBox Err.Description
    Resume Exit_cmdDeleteRecord_Click
End Sub

Open in new window

Comment
Watch Question
Remote Training and Programming
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
Unlock 2 Answers and 22 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE