DAO versus default

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

In a recent segment of code I wrote, I discovered that
when Dim'g a recordset object variable that DOA isn't
the default. E.g., one had to:

Dim dbMyDatabase as DOA.Recordset

lest one get an wrong data type error with the
"Set" OpenRecordset. What IS the default?

I also noted that when Dim'g a database object
variable that it didn't SEEM to matter if I clarified
as DOA.Database or not.
 
You have really two choices:

make sure your database does NOT have a ADO reference (just remove it),
or:

always define what type of reocrdset you are using.

If you don't define which type, then whatever reference appears first in the
list is used, and that going to cause problems.

So, the "default" actually depends on how your references are setup. I would
as suggested REMOVE the ADO references if you not using them, and then you
should for the most part be ok. (useally, whatever reference appears first
is going to be the default...so, it can change on you).
I also noted that when Dim'g a database object
variable that it didn't SEEM to matter if I clarified
as DOA.Database or not.

It should matter. Often, ms-access will make a decision about what kind of
reocrdset is returned..

set rstData = me.RecordSet

is that recordset a dao, or ado? Well, ms-access actually "casts" the
reocrdset to the type of variable you defined. So, in some cases, it can use
either type of reocrdset, but then that means some methods and use of the
roecrdset object that work in dao will NOT work if the recordset is ADO.

You really for all purposes can't leave this up to chance. Set your
references correct, and if you MUST for some reason have both ADO and DAO
refs active at the same time..then you better disambiguate the types of
recocrdsets you define...

There is no "right" or "wrong" here, but you simply need to choose a
standard, and stick to it..
 
Hi Albert!
As you might imagine, I'd already decided that one should
be explicit in such matters. But, your explanation certainly
offers sufficient caution to do just that.

Thanks,
Bill
 
It should matter. Often, ms-access will make a decision about what
kind of reocrdset is returned..

set rstData = me.RecordSet

is that recordset a dao, or ado?

Not relevant for database variables, since there is no such thing in
ADO. That's why you can get away without disambiguating it when you
have both references set. I never have both references set (I don't
use ADO), but I disambiguate all variable declarations for DAO
objects, just in case the code ever gets run in an environment with
both libraries referenced.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top