473,382 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

CurrentDb in a DAO.Database

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
3 8611
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John | last post by:
Hi In Access 2000 I have the following code; Set dbs = CurrentDb <some code to access database here> Set dbs = Nothing
4
by: Howard | last post by:
I am trying to use DoCmd.TranferSpreadsheet to import a spreadsheet into an Access table that's not the CurrentDB. I have the database open, but I don't see how to tell the TransferSpreadsheet...
2
by: WindAndWaves | last post by:
I recently made a very simple little function: Function x() Dim Tbl As TableDef Dim fld As DAO.Field Set Tbl = currentdb.TableDefs("search") Debug.Print Tbl.Name For Each fld In Tbl.Fields...
4
by: paii, Ron | last post by:
Are the following 2 bits of code equivalent. I want to use ws for transactions. Dim ws as Workspace Dim db as Database Dim rs as Recordset Set ws = DBEngine.Workspaces(0) Set db =...
1
by: jnikle | last post by:
I have a parameter query named "qry_employee_info_reports" that I need to run in the OnOpen event of a form. I'm after its total number of records. The query's got several joins in it, and one of...
7
by: Tony M. | last post by:
I'm trying to execute an append query. I have a case that works, and one that returns an object not set error. THIS WORKS: Private Sub cmdArchiveRecs_Click() BeginTrans CurrentDb.Execute...
0
by: Alan Carpenter | last post by:
I'm curious about getting to the text of procedures in a database other than the current database without a new instance of Access. Note I don't want to execute or call anything, I just want to...
1
by: sphinney | last post by:
As my Access form opens, I want it to find the names of the tables in the current Access database and populate a combobox with the table (recordset) names. Problem is, the CurrentDb.Recordsets...
2
by: RobinAG | last post by:
Hello, I'm trying to work with multiple databases (for different Fiscal Years) from within a single database. I have two backend dbs I need to pull up data from at different times, depending on...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.