473,387 Members | 1,540 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,387 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 8877
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 don't see how to tell the TransferSpreadsheet...
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 etc) located in the same directory. To make...
11
by: MLH | last post by:
If this is what MySQL is set to... SELECT DISTINCTROW qryVehiclesNowners5.SerialNum, qryVehiclesNowners5.VDescr, qryVehiclesNowners5.Owner, qryVehiclesNowners5.VehicleJobID ,...
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...
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 data from a single field in a table inside the...
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
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 form "Frm_ATandT_Activation"....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.