Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 14th, 2007, 10:37 AM
Authorized User
 
Join Date: Nov 2007
Location: Nederland, , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rst.BOF And Rst. EOF question

I understand. The book was informative. More than most of the books at the local book store. I have a cub question:
I'm a little confused on a concept.
The statement: "If Rst.BOF And Rst. EOF Then"
This seems to be for checking to see if there are any records
in the Rst.
What is the dif. between using this method or using
the statement: "If Rst.RecordCount <> 0 Then"

Also, the Me.Filter. Why do I need to place a filter
when loading a form? example:
Me.Filter = "([Drawing Number] <> '')"
Me.FilterOn = True
Isn't it filtered when using a "rst.open Select * Mytable,cnx"
??Does each form requires the me.filter statement?
Reply With Quote
  #2 (permalink)  
Old November 14th, 2007, 01:12 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The RecordCount will not necessarily contain the number of records in the recordset at the time you read it depending on the type of recordset you have opened, and depending on if you have navigated around in that recordset. This is particularly important when you are working with a read only cursor. No matter what, use the EOF method for determining if there are records you can process.

When first opening a recordset, your cursor is pointing at the first record if there is one. If there isn't, then it is pointing at EOF. I see a lot of sample code that checks BOF and EOF, but you only need to check BOF if you are navigating backwards.

Regarding yoiur "filter" question. I must be missing something, as a form does not have a filter. Is this Access code or something? I haven't messed around with recordset filters all that much, but the reason you might want them is to work with a subset of records in the recordset. This could potentially give you a performance improvement if getting data from the database is very costly.




Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
Reply With Quote
  #3 (permalink)  
Old November 14th, 2007, 05:56 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Quote:
quote:Originally posted by woodyz


When first opening a recordset, your cursor is pointing at the first record if there is one. If there isn't, then it is pointing at EOF. I see a lot of sample code that checks BOF and EOF, but you only need to check BOF if you are navigating backwards.
Woody, this is largely true, but I am addressing it so that the poster will be clearer.

It is true that when you open a recordset, the first record is the current record, if there are any records.

If there are no records, both .BOF (beginning of file) and .EOF (End of File) will be true. If .EOF is true (and that's all you know) then two situations are possible: there are no records, or you have run off the end. If .BOF is true (and that's all you know) then two situations are possible: there are no records, or you have run off the beginning of the recordset.

If you have run off the end, it is manifestly obvious that you are not at the beginning...

So if both .E– [u]and</u> .BOF are true, there cannot be anything in between, you see. Checking for both guarantees that under any arrangement, if both are true the recorset is empty.

Now, again, when you open a RecSet the first record is current—so the following is never necessary:
Code:
    rs.Open
    rs.MoveFirst
    So, since the recset is not at .BOF, but is at the first record,
Code:
    rs.Open
Code:
    If rs.BOF . . .
    is a functional shorthand to test whether any records were returned. So is
Code:
    rs.Open
Code:
    If rs.EOF . . .


Regarding using .Filter, you can use this, or you can use restriction language in the WHERE clause of the query. With .Filter, you actually return all of the records into the recordset, but you don't see them all. This can be advantageous if you are going to chnage the filter. This removes the necessity of getting records again. But if you are never going to alter which records you see, using a WHERE clause is easier on the computer resources, and probably ever-so-slightly faster.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Either BOF or EOF is True" need help! murshed Classic ASP Databases 4 March 18th, 2008 03:43 PM
rst.AddNew to a Linked Table rrenaud Access VBA 3 January 8th, 2008 10:54 PM
RST File fbezede Access 0 August 16th, 2006 02:49 PM
How to set current recordset (rst.) gasma1975 Access 1 February 11th, 2005 11:42 AM
rst.edit method Sympac Access 0 August 30th, 2004 03:50 PM



All times are GMT -4. The time now is 11:15 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.