Module: ADOJetADOX in Category Access/Jet Databases : Table and Records from Total Visual SourceBook

Code that shows how to work with Jet/Access objects and information using the ActiveX Data Objects (ADO) object model in VBA and VB6.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the modADOJetADOX module.
ADOXCreateJetDatabase Procedure Create a new Jet database using ADOX.
ADOXCreateLinkedJetTable Procedure Create a table link in the specified database using ADOX.
ADOXGetTableProperties Procedure Get the properties of a table.
ADOXGetLinkedPath Procedure Get the path where the specified linked table resides.
ADOXGetLinkType Procedure Get a string identifying the type of object a linked table represents.
ADOXIsTableLinked Procedure Determine if the specified table is a linked table.
ADOXListJetTablesCollectionToString Procedure Uses ADOX to return a list of all items in the Tables catalog collection of the specified database. Note that this collection contains tables and views, so be sure to look at the value of the Type property to determine which is which.
ADOXRelinkAllTables Procedure Relinks all the linked tables to another database (assumes all linked tables are linked to the same database).
ADOXRelinkTable Procedure Relinks a table to another database.
ADOXTestAllLinkedTables Procedure Tests all linked tables in the specified database to see if the links are valid.
ADOXTestLinkedTable Procedure Tests the specified linked table to see if its link is valid.
' Example of modADOJetADOX
'
' To try this example, do the following:
' 1. Create a new user form in your project.
' 2. Create a command button 'cmdTest'
' 3. Paste this code into the form's module

Private Const mcstrSampleFolder As String = "C:\Total Visual SourceBook 2013\Samples\"
Private Const mcstrSampleDatabase As String = mcstrSampleFolder & "Sample.mdb"
Private Const mcstrTmpSampleDatabase As String = mcstrSampleFolder & "Sample_Tmp.mdb"
Private Const mcstrTable As String = "Categories"
Private Const mcstrTable_Linked As String = "Categories_Linked"

Private Sub cmdTest_Click()
  Dim cnn As New ADODB.Connection
  Dim strJetProvider As String

  #If VBA7 Then
    strJetProvider = "Microsoft.ACE.OLEDB.14.0"
  #Else
    strJetProvider = "Microsoft.Jet.OLEDB.4.0"
  #End If

  ' Open the connection
  cnn.CursorLocation = adUseServer
  cnn.Open "Provider=" & strJetProvider & ";" & "Data Source=" & mcstrSampleDatabase

  ' Example of ADOXCreateJetDatabase
  If ADOXCreateJetDatabase(mcstrTmpSampleDatabase) Then
    Debug.Print "Database created: '" & mcstrTmpSampleDatabase & "'"
  Else
    Debug.Print "Database not created."
  End If

  ' Example of ADOChangeJetColumnCase
  Debug.Print vbCrLf & "Table List: " & vbCrLf & "--------------------------"
  Debug.Print ADOXListJetTablesCollectionToString(cnn, vbCrLf) & vbCrLf

  ' Open the connection to the new database
  With cnn
    .Close
    .CursorLocation = adUseServer
    .Open "Provider=" & strJetProvider & ";" & "Data Source=" & mcstrTmpSampleDatabase
  End With

  ' Example of ADOXCreateLinkedJetTable
  If ADOXCreateLinkedJetTable(cnn, mcstrSampleDatabase, mcstrTable, mcstrTable_Linked) Then
    Debug.Print "Linked table created."
  End If

  ' Example of ADOXIsTableLinked
  If ADOXIsTableLinked(cnn, mcstrTable_Linked) Then
    Debug.Print "Table is linked: " & mcstrTable_Linked
  Else
    Debug.Print "Table is not linked."
  End If

  ' Example of ADOXGetTableProperties
  Debug.Print vbCrLf & "Linked Table Properties:" & vbCrLf & "--------------------------"
  Debug.Print ADOXGetTableProperties(cnn, mcstrTable_Linked)

  ' Example of ADOXGetLinkedPath
  Debug.Print "Linked Table Path: " & _
    ADOXGetLinkedPath(cnn, mcstrTable_Linked)

  ' Example of ADOXGetLinkType
  Debug.Print "Link Type: " & _
    ADOXGetLinkType(cnn, mcstrTable_Linked)

  ' Example of ADOXRelinkTable
  If ADOXRelinkTable(cnn, mcstrTable_Linked, mcstrSampleDatabase) Then
    Debug.Print "Table re-linked: " & mcstrTable_Linked
  Else
    Debug.Print "Table not re-linked."
  End If

  ' Example of ADOXRelinkAllTables
  If ADOXRelinkAllTables(cnn, mcstrSampleDatabase) Then
    Debug.Print "All tables re-linked."
  Else
    Debug.Print "All tables not re-linked."
  End If

  ' Example of ADOXTestLinkedTable
  If ADOXTestLinkedTable(cnn, mcstrTable_Linked) Then
    Debug.Print "Linked table " & mcstrTable_Linked & " is valid."
  Else
    Debug.Print "Linked table " & mcstrTable_Linked & " is NOT valid."
  End If

  ' Example of ADOXTestAllLinkedTables
  If ADOXTestAllLinkedTables(cnn) Then
    Debug.Print "All linked tables are valid."
  Else
    Debug.Print "At least one linked table is NOT valid."
  End If

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS