Results 1 to 5 of 5

Thread: Database - first use

  1. #1

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    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

  2. #2
    Lively Member
    Join Date
    Nov 2000
    Posts
    82
    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.

  3. #3

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Elegantly?

  4. #4
    Lively Member
    Join Date
    Nov 2000
    Posts
    82
    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.

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    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
  •  



Click Here to Expand Forum to Full Width