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.