|
-
Nov 19th, 2000, 10:05 AM
#1
Thread Starter
Fanatic Member
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
-
Nov 19th, 2000, 10:34 AM
#2
Lively Member
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.
-
Nov 19th, 2000, 01:41 PM
#3
Thread Starter
Fanatic Member
-
Nov 19th, 2000, 01:46 PM
#4
Lively Member
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.
-
Nov 20th, 2000, 06:51 AM
#5
Fanatic Member
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.
Not nearly so tired now...
Haven't been around much so be gentle...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|