Data Control to ADO Code

How would you turn this into ADO code?

If Data1.Database.TableDefs("DBRecords").Name <> "DBRecords" Then create_dbrecords
If Data1.Database.TableDefs("musicians").Name <> "musicians" Then musicians
If Data1.Database.TableDefs("all_users").Fields("Birthday").Name <> "Birthday" Then UpgradeMDB
If Data1.Database.TableDefs("all_users").Fields("Music").Name <> "Music" Then UpgradeMDBII
If Data1.Database.TableDefs("email_offline").Name <> "email_offline" Then Email_Offline
If Data1.Database.TableDefs("event_invite").Name <> "event_invite" Then Event_Invite
If Data1.Database.TableDefs("advert_via_event_log").Name <> "advert_via_event_log" Then advert_via_event_log
If Data1.Database.TableDefs("live_shows").Name <> "live_shows" Then live_shows
Takamine334Asked:
Who is Participating?
 
jkaiosIT DirectorCommented:
Use both ADO and ADOX to accomplish this.

1. Add "Microsoft ActiveX Data Objects 2.x Library" and "Microsoft ADO Ext. 2.x for DDL and Security" via the Projects->References menu.

2. Copy sample code below into a new project and run it.


Option Explicit

Private Sub Form_Load()

   Dim oCN As New ADODB.Connection
   Dim oRS As New ADODB.Recordset
   
   With oCN
      .Provider = "Microsoft.JET.OLEDB.4.0"
      .Properties("Data Source") = "C:\YOURDB.MDB"       '<== CHANGE THIS TO YOUR ACTUAL DB NAME AND PATH
      .Open
   End With
   
   If oCN.State = adStateOpen Then
      showTables oCN
   End If

End Sub

Private Sub showTables(oCN As ADODB.Connection)

   Dim oCat As New ADOX.Catalog
   Dim oTbl As New ADOX.Table
   
   oCat.ActiveConnection = oCN
   
   '--- For Each oTbl In oCat.Tables
   '---   Debug.Print oTbl.Name, oTbl.Type
   '--- Next
   
   If oCat("DBRecords").Name <> "DBRecords" Then Debug.Print "create_dbrecords"
   If oCat("musicians").Name <> "musicians" Then  Debug.Print "musicians"
   If oCat("all_users").Columns("Birthday").Name <> "Birthday" Then  Debug.Print "UpgradeMDB"
   If oCat("all_users").Columns("Music").Name <> "Music" Then  Debug.Print "UpgradeMDBII"
   If oCat("email_offline").Name <> "email_offline" Then  Debug.Print "Email_Offline"
   If oCat("event_invite").Name <> "event_invite" Then  Debug.Print "Event_Invite"
   If oCat("advert_via_event_log").Name <> "advert_via_event_log" Then  Debug.Print "advert_via_event_log"
   If oCat("live_shows").Name <> "live_shows" Then  Debug.Print "live_shows"
   
End Sub
0
 
ClifCommented:
You would need to create a database object, open it to the correct database, and then search and replace "Data1.Database" with the name od the database object:

Dim MyDB As Database
Set MyDB = OpenDatabase("c:\myAccessDB.mdb")
If MyDB.TableDefs("DBRecords").Name <> "DBRecords" Then create_dbrecords
If MyDB.TableDefs("musicians").Name <> "musicians" Then musicians
If MyDB.TableDefs("all_users").Fields("Birthday").Name <> "Birthday" Then UpgradeMDB
If MyDB.TableDefs("all_users").Fields("Music").Name <> "Music" Then UpgradeMDBII
If MyDB.TableDefs("email_offline").Name <> "email_offline" Then Email_Offline
If MyDB.TableDefs("event_invite").Name <> "event_invite" Then Event_Invite
If MyDB.TableDefs("advert_via_event_log").Name <> "advert_via_event_log" Then advert_via_event_log
If MyDB.TableDefs("live_shows").Name <> "live_shows" Then live_shows
0
 
Takamine334Author Commented:
oh, that's it? for ADO code?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
ClifCommented:
Oh, heck.  What was I thinking...

Sorry about that.  It's late in the day.  :(
0
 
Takamine334Author Commented:
So, thats not the answer? Guess not.
0
 
bugs021997Commented:
<%
Dim myConn
Set myConn = Server.CreateObject("ADODB.Connection")
myConn.Open = ("DRIVER={Microsoft Access" &_
" Driver (*.mdb)};DBQ=" &_
"C:\myAccessDB.mdb;")

strSQL="SELECT * FROM YOUR TABLE"
set rs = server.createObject("ADODB.Recordset")
rs.open strSQL, db, 2, 2

If rs("COLUMN_NAME") <> "CONDITION" Then create_dbrecords
//PUT ALL YOUR CODITIONS HERE...



rs.close
set rs=nothing

myConn.Close()
Set myConn = nothing

%>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.