Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 10th, 2006, 10:44 AM
Authorized User
 
Join Date: May 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Understanding Recordsets?

I have some questions about recordset and hoping for help.

1. When opening a recordset, Why is there code to check for the recordcount when we know that records exist?
          "If Rst.RecordCount <> 0 Then"

2. How does the code know where to place the pointer or where does the pointer start? What happens when it opens a recordset?

3. Can anyone explain the general practice in handling recordset?
   Something I can use as a go-bye when writing code?

This is basic concept questions, for some reason recordset is a mystery to me and I'm having a hard time understanding the basics.
Thanks

John Paul
__________________
John Paul
 
Old May 10th, 2006, 01:07 PM
Authorized User
 
Join Date: Apr 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

> 1. When opening a recordset, Why is there code to check for
> the recordcount when we know that records exist?
> "If Rst.RecordCount <> 0 Then"

I'm not quite sure what you meant by your question, so I'm just going to answer it the way I interpret it - Even if you know there are records, you generally want to write your code so that it can handle the situations like no data, just in case. By the way, another way to test for no data is:

           "If Rst.BOF and Rst.EOF Then"

The record set will be at the beginning and end of the "File".

> 2. How does the code know where to place the pointer or where
> does the pointer start? What happens when it opens a recordset?

If by pointer, you mean the recordset pointer, in Access 2000 and above, it is automatically placed at the first record in your record source, be that a table or the results of a query. In earlier versions you had to move to the first record before it became current using something like "Rst.MoveFirst". Incidentally, in versions before 2000 you had to do an "Rst.MoveLast" before you could accurately know the total number or records in your recordset, which is why the BOF and EOF check was better.

> 3. Can anyone explain the general practice in handling recordset?
> Something I can use as a go-bye when writing code?

Hmm, that really depends on what you need to do. In general, you open them up, read/write data, and then close them. Recordsets can thought of as your own private window on the data, sort of a virtual table. Unlike views in Oracle, you get a lot of extra data in the Recordset, so you can simply access the data like you would in SQL*PL or dive deeply into information in the recordset, such as the field names and their data types, and a lot more. You do need to realize that recordsets are generalized so depending on where you're getting your data from, SQL Server, Access, Oracle, etc., you will get your data, but some of the features in the recordset may not apply. For details on recordsets I suggest you get some of the beginner books on Access VBA the WROX has.

Good luck.

 
Old May 10th, 2006, 07:18 PM
Authorized User
 
Join Date: Jul 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

2) As a general rule, I always move the pointer to the last record and then to the first record when using record sets. I'm not sure why, but sometimes the point will not go to the first record???

Dim SQL as string
Dim rst as recordset

SQL = "Your qry"
Set rs = currentdb.openrecordset(SQL)

With rs
.movelast
.movefirst

'your code

end with
rs.close









Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help understanding DataRow asp_convert ADO.NET 3 March 13th, 2007 02:39 PM
Need help understanding databinding asp_convert ASP.NET 2.0 Basics 0 February 11th, 2007 07:17 PM
Understanding Axes Chamkaur XSLT 1 August 6th, 2006 03:09 PM
understanding Variable use imroostercogburn C++ Programming 7 July 28th, 2006 06:15 PM
Understanding Session rajuru Beginning PHP 2 September 25th, 2004 05:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.