Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link a Table through VBA

How To

Link a Table through VBA

by  hwkranger  Posted    (Edited  )

Code:
Public Function LinkTable(strLocalName As String, strSourceName As String, strSourceLocation As String, blnHideTable as boolean)
'Links a table to the current project
If fFindTable(strLocalName) Then
    DoCmd.DeleteObject acTable, strLocalName
End If
    DoCmd.TransferDatabase acLink, "Microsoft Access", strSourceLocation, acTable, strSourceName, strLocalName
    
    Dim tb As New ADOX.Table
    Dim cat As New ADOX.Catalog
    
    cat.ActiveConnection = CurrentProject.Connection
    Set tb = cat.Tables(strLocalName)
    tb.Properties("Jet OLEDB:Table Hidden In Access") = blnHideTable 
    
End Function

Requires:

Code:
Public Function fFindTable(strTableName As String, Optional cn As ADODB.Connection) As Boolean
  Dim rs As ADODB.Recordset
  'Set cn = New ADODB.Connection
  If cn Is Nothing Then
    Set cn = CurrentProject.Connection
  End If
  
  Set rs = cn.OpenSchema( _
         adSchemaTables, Array(Empty, Empty, strTableName))
  fFindTable = Not rs.EOF
  rs.Close
  Set rs = Nothing
End Function
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top