article

Convert DAO to ADO

Email
Submitted on: 1/26/2015 9:27:00 AM
By: Morgan Haueisen (from psc cd)  
Level: Advanced
User Rating: By 2 Users
Compatibility: VB 6.0
Views: 4250
 
     This will give you the tools and instructions necessary to convert your DAO project to ADO.

This article has accompanying files
 
				



To convert your DAO project just follow these steps



Here are 9 steps to convert your DAO project to ADO. I have included version numbers but yours may vary.

I have also included a sample BAS file that will create an Access database file. Use this file as a model to create your own or you can download some nice code that will make this task much easier.

See http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=22085&lngWId=1

1. Add the following references to your project:

  • Microsoft ActiveX Data Objects 2.6 Library
  • Microsoft ADO Ext. 2.5 for DDL and Security
  • Microsoft Jet and Replication Objects 2.5 Library

2. Remove references to Microsoft DAO 3.6 Object Library

3. Add the component Microsoft ADO Data Control (if required)

4. Replace any data bound controls with their ADO equivalents

Examples:

  • Microsoft Data Bound Grid with Microsoft DataGrid Control (OLEDB)
  • Microsoft Data Bound List with Microsoft DataList Control (OLEDB)
  1. Add the attached BAS and CLS files to your application.
  • clsADOConnect.cls
  • modADO.bas
  • modADOdc.bas (only needed if you are using the ADO Data control)

6. Search your project for the following and replace as shown:

  • Dim MyDB As Database WITH Dim MyDB As ADODB.Connection
  • Dim MySet As Recordset WITH Dim MySet As ADODB.Recordset
  • Set MyDB = Workspaces(0).Opendatabase(dbFileName) WITH Call OpenDB(MyDB, , dbFileName)
  • Set MySet = MyDB.Openrecordset("Select * From Table") WITH Call OpenRS(MySet, "Select * From Table", MyDB)
  • Data1. DatabaseName= dbFileName AND Data1. RecordSource WITH ADOdcConnect(Data1, "Select * From Table", dbFileName)

The Following is true for FindFIrst, FindNext, FindLast, FindPrevious:

  • MySet.FindFirst "[LastName]=’Haueisen’" WITH ADOFindFirst(MySet, "[LastName]=’Haueisen’")
  • If MySet.NoMatch then WITH If Not ADOFindFirst(MySet, "[FieldName]=’Morgan’") then

The Following is true for FindFIrst, FindNext, FindLast, FindPrevious:

  • Data1.Recordset.FindFirst "[LastName]=’Haueisen’" WITH ADOdcFindFirst(MySet, "[LastName]=’Haueisen’")
  • If Data1.Recordset.NoMatch then WITH If Not ADOdcFindFirst(MySet, "[FieldName]=’Morgan’") then
  • Move your code from Data1_Reposition() to Data1_MoveComplete()
  • Move your code from Data1_Validate () to Data1_WillChangeRecord () and modify as necessary (Save = False to adStatus = adStatusCancel).
  • If you are using queries such as "Select * From Table Where [LastName] LIKE ‘Ha*’" you need to change them to look like "Select * From Table Where [LastName] LIKE ‘Ha%’"

7. Remove all MySet.Edit

  1. Use the following as needed:
  • ADOAttachTable
  • ADOCreateQuery
  • ADODeleteQuery
  • InitSettings (does some system stuff)
  • GetUserName (Returns a user’s login ID)

9. Test., Test, Test.

  • ADO follows the SQL rules for writing queries; so you may need to make some changes to any queries you have imbedded in your code. For example the word Size is a key word and this is the reason for the last line under step 6.

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 21 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.