472,330 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

currentdb vs databases(0)

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 = ws.Databases(0)

--------------------------------

Dim ws as Workspace
Dim db as Database
Dim rs as Recordset

Set ws = DBEngine.Workspaces(0)
Set db = CurrentDb
Nov 13 '05 #1
4 8787
I think you're better off using the first one, so that you're guaranteed
that you've got the appropriate database reference.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"paii, Ron" <pa**@packairinc.com> wrote in message
news:k9********************@athenet.net...
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 = ws.Databases(0)

--------------------------------

Dim ws as Workspace
Dim db as Database
Dim rs as Recordset

Set ws = DBEngine.Workspaces(0)
Set db = CurrentDb

Nov 13 '05 #2
Douglas J. Steele wrote:
I think you're better off using the first one, so that you're
guaranteed that you've got the appropriate database reference.


The first one in his message body or the first one in his subject line?
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #3
Oops, you're right: I was a little ambiguous, wasn't I?

I meant his first code sample (using Databases(0))

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:c7*****************@newssvr11.news.prodigy.co m...
Douglas J. Steele wrote:
I think you're better off using the first one, so that you're
guaranteed that you've got the appropriate database reference.


The first one in his message body or the first one in his subject line?
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #4
"paii, Ron" <pa**@packairinc.com> wrote in
news:k9********************@athenet.net:
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 = ws.Databases(0)

--------------------------------

Dim ws as Workspace
Dim db as Database
Dim rs as Recordset

Set ws = DBEngine.Workspaces(0)
Set db = CurrentDb


Just about everything you want to know was last discussed in this
thread:

http://groups-beta.google.com/group/comp.databases.ms-
access/msg/d530
add6df407824

That's my first post in the thread, which you can use to bring up
the treeview of the entire thread.

In short:

1. if your operations are on the currently opened database (the
front end), use CurrentDB().

2. if your operations are on a different db, use DBEngine and open a
different database/workspace, as necessary.

Actually, looking back on your coded examples, they are *not*
equivalent. In the second case, setting the workspace serves
absolutely no function.

And, of course, you can get the database pointer from
DBEngine.Workspaces(0).Databases(0), which can be abbreviated as
DBEngine(0)(0) because those are the default collections.

If you are doing transactions and need to use a workspace, you'll
use DBEngine.Workspace(0) or open a new one. CurrentDB() and
DBEngine(0)(0) have nothing to do with it.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
5
by: Vladislav Moltchanov | last post by:
I am making data entry tool in Acc2K for several data collecting centres. It is convenient to have several files (mde file, .mdb with tables only...
11
by: MLH | last post by:
If this is what MySQL is set to... SELECT DISTINCTROW qryVehiclesNowners5.SerialNum, qryVehiclesNowners5.VDescr, qryVehiclesNowners5.Owner,...
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...
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...
3
by: Richard Hollenbeck | last post by:
In DAO, is there any difference between "set db = CurrentDb()" with parentheses and "set db = CurrentDb" without parentheses? I'm just looking for...
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)...
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...
1
MitchR
by: MitchR | last post by:
Hello Folks; I have run myself into a hole I cannot get of and need some assistance. I have a Form "Frm_ATandT_Activation_Center" that has a sub...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

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.