Scan with Object or DAO.Recordset
am 25.12.2007 22:30:42 von Johnie
To scan through a table and edit values I can use OpenRecordset with:
1. Dim rst As Object etc., or
2. Dim rst As DAO.Recordset etc.
Is there a performance difference between the two or are there reasons why I
should be using one in stead of the other?
Thanks,
John
Re: Scan with Object or DAO.Recordset
am 26.12.2007 01:45:42 von Allen Browne
The rule of thumb is to use the most specific data type you can.
Recordset is much more specific than Object.
(Variant is even broader yet.)
The only reason the Wizard usings Object is because Microsoft tried to
introduce ADO recordsets into Access 2000, where previous versions had use
DAO recordsets. So Object was the narrowest type they could use (since the
Recordset object from the ADO library and the DAO library require
disambiguating.) But when you write code, you know the library you are
using, so:
Dim rst AS DAO.Recordset
is much better code.
One reason it's better is that Access is able to verify your code uses the
correct methods and properties of that specific type. Using Object it can't
verify the compilation. It can't offer all the right things in the
Intellisense lists as you type the code either.
In summary, use the most specfic data type you can, and the narrowest scope
you can.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
wrote in message
news:fkrsq0$288l$1@textnews.wanadoo.nl...
> To scan through a table and edit values I can use OpenRecordset with:
> 1. Dim rst As Object etc., or
> 2. Dim rst As DAO.Recordset etc.
> Is there a performance difference between the two or are there reasons why
> I should be using one in stead of the other?
>
> Thanks,
> John
Re: Scan with Object or DAO.Recordset
am 26.12.2007 11:04:43 von Johnie
Thanks Allen.
John
"Allen Browne" schreef in bericht
news:4771a438$0$6841$5a62ac22@per-qv1-newsreader-01.iinet.ne t.au...
> The rule of thumb is to use the most specific data type you can.
> Recordset is much more specific than Object.
> (Variant is even broader yet.)
>
> The only reason the Wizard usings Object is because Microsoft tried to
> introduce ADO recordsets into Access 2000, where previous versions had use
> DAO recordsets. So Object was the narrowest type they could use (since the
> Recordset object from the ADO library and the DAO library require
> disambiguating.) But when you write code, you know the library you are
> using, so:
> Dim rst AS DAO.Recordset
> is much better code.
>
> One reason it's better is that Access is able to verify your code uses the
> correct methods and properties of that specific type. Using Object it
> can't verify the compilation. It can't offer all the right things in the
> Intellisense lists as you type the code either.
>
> In summary, use the most specfic data type you can, and the narrowest
> scope you can.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.