Solved

Recordcount EOF MoveLast

Posted on 2000-02-28
4
499 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
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 69

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now