By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,618 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

CurrentDb in a DAO.Database

P: n/a
In DAO, is there any difference between "set db = CurrentDb()" with
parentheses and "set db = CurrentDb" without parentheses? I'm just looking
for data from a single field in a table inside the same Access database, if
that means anything. I forgot to put the blank parentheses but I'm not
finished building the recordset. I'm betting it will work just fine. Why
and when (and what) would anything go inside those parentheses?
Jul 3 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
No practical difference.

My personal preference is to use the parentheses, as a reminder that it
behaves like a function (returning a fresh instance.)

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

"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:j47qg.982$543.690@trnddc04...
In DAO, is there any difference between "set db = CurrentDb()" with
parentheses and "set db = CurrentDb" without parentheses? I'm just
looking for data from a single field in a table inside the same Access
database, if that means anything. I forgot to put the blank parentheses
but I'm not finished building the recordset. I'm betting it will work
just fine. Why and when (and what) would anything go inside those
parentheses?

Jul 3 '06 #2

P: n/a
"Allen Browne" <Al*********@SeeSig.Invalidwrote in
news:44**********************@per-qv1-newsreader-01.iinet.net.au:
"Richard Hollenbeck" <ri****************@verizon.netwrote in
message news:j47qg.982$543.690@trnddc04...
>In DAO, is there any difference between "set db = CurrentDb()"
with parentheses and "set db = CurrentDb" without parentheses?
I'm just looking for data from a single field in a table inside
the same Access database, if that means anything. I forgot to
put the blank parentheses but I'm not finished building the
recordset. I'm betting it will work just fine. Why and when
(and what) would anything go inside those parentheses?

No practical difference.

My personal preference is to use the parentheses, as a reminder
that it behaves like a function (returning a fresh instance.)
I do what Allen does, as well. Without the () you're using a method
of the application object, with it, you're using a function. I think
the function makes more sense conceptually, given what that it
returns a copy, not the original.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 3 '06 #3

P: n/a
Richard Hollenbeck wrote:
In DAO, is there any difference between "set db = CurrentDb()" with
parentheses and "set db = CurrentDb" without parentheses? I'm just looking
for data from a single field in a table inside the same Access database, if
that means anything. I forgot to put the blank parentheses but I'm not
finished building the recordset. I'm betting it will work just fine. Why
and when (and what) would anything go inside those parentheses?
VBA is a sloppy language which allows but does not require the Function
operator, (), for Functions which have no parameters. But surely,
CurrentDB() and CurrentDB are one and the same thing.

If we create our own !!!somewhat!!! similar function we can refer to it
with or without the parentheses. Regardless, it's still a function.

Public Function MyDB() As DAO.Database
Set MyDB = DBEngine(0)(CurrentProject.FullName)
With MyDB
.TableDefs.Refresh
.QueryDefs.Refresh
End With
End Function

Sub temp()
Debug.Print MyDB.TableDefs.Count
Debug.Print MyDB().TableDefs.Count
End Sub

VB and VBA can be powerful programming languages but their sytnax is
absurd.

IMO DBEngine(0)(CurrentProject.FullName) for those who use wizards or
DBEngine(0)(0) for those who don't is preferable to CurrentDB()
[assuming a modern version of Access]. DBEngine(0)(0) would be
universally good save for the irresponsible coding of the wizard makers
of Redmond.

Jul 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.