[quoting me:]
That might be correct under some certain circumstances; however
the direction of logic flow might be wrong. As with other forms of
late binding it can be written as early binding and then move to
late binding when done. This would mean we still use DAO and then
remove the DAO reference which is the reverse of what is quoted.
???
Not "use" as in "writing code" but "use" as in "at runtime the code
executes using DAO."
Late binding is slower than early binder, both in initializing and
in traversing properties/methods. Now, it may not be enough slower
to matter, but the lack of any justification for late binding DAO in
the first place makes this performance sacrifice useless. And it
*could* make a difference in particular types of scenarios.
The ‘why’ of doing so I think I have already posted. We late
bind in order to try and preserve portability.
And there's absolutely no portability issue in Access.
DAO was not referenced in Access 2000 so any
code that used variables declared as DAO.SomethingOrOther would
fail because of the lack of a DAO reference in Tool>References.
Yes it’s easy to fix, but why have to fix something that needed
not to be broken in the first place?
It should be fixed because any A2K app that lacks the DAO reference
is written by someone who doesn't know what they are doing. Either
they didn't use DAO in code before that point or they are using ADO.
In either case, their app is wrongly-designed for what they are
trying to do, precisely because they didn't know they need to
rectify Microsoft's design error in not setting the default DAO
reference.
So where possible at the procedure level, we can write it in such
a way that it works no matter where it’s used. This to means the
code is better because it’s more portable but there is more to
it than just that.
I disagree that this is a priority that should drive the design of
code.
[]
That should run in any version of Access from 97 and up.
So the question becomes; why compromise that portability by
declaring a variable that requires as DAO reference?
Because it's better design. It will be more understandable by more
programmers. It will execute faster. It will compile more reliably.
It will be more easily maintained. It will use memory more
efficiently.
The other point, and really the reason I started writing it that
way a lot of years ago, is that we circumvent the old hackney
argument about having to set variables to nothing when finished
with them. In the above case the argument is circumvented because
there is no variable set to something and, therefore, no
requirement to set it to nothing.
But your example works in only one type of circumstance. There are
numerous cases where it does *not* work. I'm all for using With
blocks where they make sense, but as your method of avoiding DAO
early binding, it seems misguided.
Indeed, if I were going with your approach, I'd still cache a
reference to CurrentDB as I do with normal early binding of DAO,
rather than needing to set up the With block all the time.
Also, to me, the chief loss of late binding is strongly typed
variables for your workspaces and databases and recordsets and
fields. This makes the code harder to debug and less efficient when
it runs. Yes, of course, you could do your programming with early
binding and switch to late binding for production, but why bother?
There is no gain whatsoever to doing so except for the silly
portability argument you're making.
So, if I’m allowed to be a little humours here, I’m not being
argumentative, I’m being non- argumentative. ;-)
I think your argument is insanely unrealistic and misguided and will
say so at length in order to try to prevent your leading someone
down the garden path.
In any case, this but a small part of something much larger.
The larger thing is about writing code in such a way that tries to
work under all circumstances, and that‘s not an easy task.
I think this is an overblown artifical requirement that you're
applying to a coding environment that is very stable and entirely
reliable with early binding (and the one case in which it is not is
fixable in 1 second -- anyone who doesn't know how to do that
shouldn't be copying VBA code from elsewhere into their current
app).
[completely irrelevant examples of SQL compatibility deleted]
The point being, try not to write a procedure that is dependant on
an outside influence and not even make the assumption that the
reference to DAO will be present.
You're comparing a 747 to a gnat.
There is absolutely no significant issue with portability for code
writting using early binding in DAO. The only minor issue you've
adduced (the A2000 issue) is so easily rectified that I just don't
understand why you're recommending that someone spend so much more
time coding with late binding (or wasting the time of switching from
early to late binding for production) just to save the time of
adding the DAO reference in any A2000-created MDB that lacks it.
Your priorities are just completely upside-down.