?
Solved

Recordcount EOF MoveLast

Posted on 2000-02-28
4
Medium Priority
?
506 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 150 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

801 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