-
I have an app that uses a database to keep reecords on students. I have a cmdAddNew button for adding a new student and cmdEnter button with this code:
Private Sub cmdEnter_Click()
Data1.Refresh
Data1.Recordset.MoveLast
End Sub
The problem is when start from a blank database there is no "last record" for it to go to. The reason I had this code here is because I need it to show the last record entered when I click cmdEnter. How will I do this when I am starting from an empty database?
I hope I explained this well enough any help is greatly appreciated.
JO
-
Although you could program this more elegantly, a simple fix is:
Code:
On Error Resume Next
An empty database will trigger the error, but no harm, no foul. Stick this just before the "MoveLast" command.
-
-
Sorry...I'm just not a big fan of the data control. I much prefer to code the required routines. Also, whenever I have to use the "On Error Resume Next" (and I do...a lot), I figure I haven't done a very good job.
-
Use the .EOF and .BOF markers to check whether or not there is data.
e.g.
Code:
If Not(Data1.Recordset.BOF And Data1.Recordset.EOF) then
Data1.Recordset.MoveLast
End If
If the .EOF and .BOF markers are both true, there is no data in the recordset.
Elegant and simple.
Paul.