473,373 Members | 1,155 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,373 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 8874
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: 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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.