Solved

Recordcount EOF MoveLast

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

Suggested Solutions

Title # Comments Views Activity
Computer crashes, following error message in event manager 5 280
MsgBox 4 71
checkbox to hide entire section 10 63
Win 10 Automation Error with .doCmd in Access 2 31
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

730 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