Solved

Recordcount EOF MoveLast

Posted on 2000-02-28
4
505 Views
Last Modified: 2008-02-01
I have some code(vb 6) to test the recordcount, below the =====.

It works sometimes but after I delete all records from the table it retains the old recordcount. Also how would I use EOF or BOF(I've been playing with it unsuccessfully for about 2 days.( an example would definitly keep me from a meltdown)

====================================

Private Sub Test_Interactions()

    Dim chk_num As Integer
    chk_num = 0
    Set db_chk = OpenDatabase("c:\Database\Porkchop.mdb")
    Set rs_chk = db_chk.OpenRecordset("Snausage_Table")
   
    chk_num = rs_chk.RecordCount
       
    If chk_num = 0 Then
        num_ClientInteractions = 1
    Else

         rs_chk.MoveLast
         'rs_chk.EOF 'Why DOESN'T THIS WORK
         chk_num = rs_chk.RecordCount
         num_ClientInteractions = chk_num + 1

    End If
End Sub
0
Comment
Question by:diek_nf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Expert Comment

by:dosyl
ID: 2565382
When you delete you should to do a .MovePrevious.
0
 
LVL 18

Accepted Solution

by:
deighton earned 50 total points
ID: 2565409
You need to close the recordset and database at some point.

Also

            Private Sub Test_Interactions()

                       Dim chk_num As Integer
                       chk_num = 0
                       Set db_chk = OpenDatabase("c:\Database\Porkchop.mdb")
                       Set rs_chk = db_chk.OpenRecordset("Snausage_Table",dbopenDynaset)
                       
                   rs_chk.movelast      
                       chk_num = rs_chk.RecordCount
                  rs_chk.movefirst

                   if rs_chk.eof = True and rs_chk.bof = True then
                        msgbox "Empty file"
                  endif
                                       
                       If chk_num = 0 Then
                           num_ClientInteractions = 1
                       Else

                            rs_chk.MoveLast
                            msgbox rs_chk.EOF
                            chk_num = rs_chk.RecordCount
                            num_ClientInteractions = chk_num + 1

                       End If


                   End Sub
0
 

Author Comment

by:diek_nf
ID: 2565478
deighton,
Could you please expand a little on EOF and BOF. I understand that they stand for end of file and beginning of file. Do I have to use eof with bof, will it work with no records. I truly appreciate your help. Thank you. This help exchange is the best supported and most helpful faq I have come across.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2565512
The EOF property is a boolean indicating if you are placed on the record past the last real record.

Your code should look like this:
Private Sub Test_Interactions()

    Dim chk_num As Integer
    chk_num = 0
    Set db_chk = OpenDatabase("c:\Database\Porkchop.mdb")
    Set rs_chk = db_chk.OpenRecordset("Snausage_Table")
   
    chk_num = rs_chk.RecordCount
         
    If chk_num = 0 Then
        num_ClientInteractions = 1
    Else

         rs_chk.MoveLast
         if not (rs_chk.BOF and rs_chk.EOF ) then
            chk_num = rs_chk.RecordCount
         else
             chk_num = 0
         endif
         num_ClientInteractions = chk_num + 1

    End If
End Sub
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question