473,412 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,412 developers and data experts.

DAO or ADO - Why Not Both?

ADezii
8,834 Expert 8TB
Whether to use DAO or ADO is sometimes a tricky question. By simply changing the value of a compile-time constant, USEDAO, you can selectively choose to use either Object Library within you code. Here is the procedure to follow:

1. Set References to both the DAO and ADO Object Libraries. In my specific case, this would be:
Expand|Select|Wrap|Line Numbers
  1. Microsoft DAO 3.6 Object Library
  2. Microsoft ActiveX Data Objects 2.1 Object Library 
2. Declare your compile-time constant within the General Declarations Section of your Form's Code Module:
Expand|Select|Wrap|Line Numbers
  1. #Const USEDAO = True        'will use DAO, for now 
3. Sample demonstration code:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "SELECT * FROM Employees ORDER BY [LastName]"
  4.  
  5. #If USEDAO Then     '#Const USEDAO = True
  6.   Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  7.   Set MyDB = CurrentDb()
  8.   Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
  9.  
  10.   Do While Not MyRS.EOF
  11.     'Example of Recordset processing
  12.     Debug.Print MyRS![FirstName] & " " & MyRS![LastName]
  13.     MyRS.MoveNext
  14.   Loop
  15. #Else     '#Const USEDAO = False, USE ADO
  16.   Dim MyRS As ADODB.Recordset
  17.   Set MyRS = New ADODB.Recordset
  18.  
  19.   Set MyRS.ActiveConnection = CurrentProject.Connection
  20.   With MyRS
  21.     .CursorType = adOpenStatic
  22.     .LockType = adLockReadOnly
  23.     .Open strSQL
  24.   End With
  25.  
  26.   'You can also use the single line syntax
  27.   'MyRS.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly, adCmdText
  28.  
  29.   Do While Not MyRS.EOF
  30.     'Example of Recordset processing
  31.     Debug.Print MyRS![FirstName] & " " & MyRS![LastName]
  32.     MyRS.MoveNext
  33.   Loop
  34. #End If 
4. If you wanted to use ADO for this exercise, change the compile-time constant to False:
Expand|Select|Wrap|Line Numbers
  1. #Const USEDAO = False        'will use ADO now 
Mar 31 '07 #1
4 7379
when we can use ado and when we can use dao??
Jun 6 '10 #2
ADezii
8,834 Expert 8TB
They are interchangeable in many circumstances, but here are a few points to remember:
  1. ADO is the premier Access Data Technology, but does not perform as well as Jet and DAO when working with Data stored in *.mdb files.
  2. ADO is the Default Data Access Object Model when you create a New *.mdb or *.adp file in Access 2002.
  3. If you create a Bound Form in an *.mdb file, the Form's Recordset will be a DAO Recordset.
  4. When working with Server Data, ADO is usually the better choice.
Jun 6 '10 #3
@ADezii
thank you very much
Jun 7 '10 #4
ADezii
8,834 Expert 8TB
You are quite welcome.
Jun 7 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Cindy | last post by:
On Thu, 3 Jul 2003 17:23:22 +0800, "Cindy" <stayhardsg@yahoo.com.sg> wrote: >Would appreciate if someone could point me to a website to find a javascript >that could perform the following: >...
2
by: maddog | last post by:
My works are done in vs.net. I wanna take a look at vs.net2003. any suggestion are welcome. thanks. -- maddog
2
by: faktujaa | last post by:
Hi, I have created an application that uses IIS to host remote components. All the remote components are listed in app.config in client and web.config in server. Now the app.config can contain...
1
by: Bob N5 | last post by:
I am working on an application that uses interop to do some simple operations with both Excel and Word. I have most of functionality working, but ran into issues on making things work with both...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
102
by: BoogieWithStu22 | last post by:
I am running into a problem with a web page I have created when viewing it in IE6 on some machines. The page has a database lookup. The user enters an account name or number and clicks a lookup...
4
by: Jim Carlock | last post by:
I'm working with three column layouts without tables. The page in question... http://www.microcosmotalk.com/images/garden/vine.asp Using clear:both; causes problems in the left and right...
14
by: Monty | last post by:
Hello, I have created a solution which has both a web UI and a winform UI, the latter is just for administrators. The Web UI (a Web Application Project) and the winform project both...
2
by: rjmckay | last post by:
At work (with restricted permissions) ... I share a desk with another person. I have a USB hub that both of us hook our headphones up to. The problem is, that sound doesn't go to both...
8
by: tshad | last post by:
I have a VS 2008 project that is going to create a Class Library. Can I use both C# and VB files to create this? I have 3 classes that are in C# and 4 that are in VB and would like to put them...
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: 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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.