469,323 Members | 1,575 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

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 8589
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Vladislav Moltchanov | last post: by
3 posts views Thread by Richard Hollenbeck | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.