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
Solved

Recordcount EOF MoveLast

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

840 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