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.
|