Connecting Tech Pros Worldwide Forums | Help | Site Map

currentdb vs databases(0)

paii, Ron
Guest
 
Posts: n/a
#1: Nov 13 '05
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



Douglas J. Steele
Guest
 
Posts: n/a
#2: Nov 13 '05

re: currentdb vs databases(0)


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" <paii@packairinc.com> wrote in message
news:k9SdnYcH1-DY1g_fRVn-ig@athenet.net...[color=blue]
> 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
>
>[/color]


Rick Brandt
Guest
 
Posts: n/a
#3: Nov 13 '05

re: currentdb vs databases(0)


Douglas J. Steele wrote:[color=blue]
> I think you're better off using the first one, so that you're
> guaranteed that you've got the appropriate database reference.[/color]

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


Douglas J. Steele
Guest
 
Posts: n/a
#4: Nov 13 '05

re: currentdb vs databases(0)


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" <rickbrandt2@hotmail.com> wrote in message
news:c7uke.1990$TJ2.1581@newssvr11.news.prodigy.co m...[color=blue]
> Douglas J. Steele wrote:[color=green]
>> I think you're better off using the first one, so that you're
>> guaranteed that you've got the appropriate database reference.[/color]
>
> 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
>[/color]


David W. Fenton
Guest
 
Posts: n/a
#5: Nov 13 '05

re: currentdb vs databases(0)


"paii, Ron" <paii@packairinc.com> wrote in
news:k9SdnYcH1-DY1g_fRVn-ig@athenet.net:
[color=blue]
> 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[/color]

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
Closed Thread