Hi Sinndho,
I revised my code somewhat and created a few more challenges.
I was trying to get a warm feeling that the refresh is definitely working by checking the record count after the refresh.
When I run the code, first I get a prompt to "Select Data Source". Should not happen, the connection string should take care of this.
I clicked on Machine Data Source and chose my Oracle Data Source.
I eventually received a "Oracle ODBC Driver Connect" prompt which I enter user name and password. Click "OK"
Chugs for awhile and eventually I receive:
Quote:
Run-time error '3146':
ODBC--call failed.
|
I tried changing my connection string from
Code:
strConnect = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strDbPath & strDb & ";" & _
"UID=" & strOraUID & ";" & _
"PWD=" & strOraPWD
Code:
strConnect = "Provider=OraOLEDB.Oracle;" & _
"Data Source=(DESCRIPTION=(CID=myCID)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHost)(PORT=1521)))(CONNECT_DATA=(SID=mySID)(SERVER=SHARED)));" & _
"User Id=" & strOraUID & ";" & _
"Password=" & strOraPWD
But I still receive the DSN and Oracle ODBC Driver Connect prompts and eventually the ODBC--call faled
Full code below,
Thx
w
Code:
Option Explicit
Sub RefreshLinksDAO()
'Comments: 1.)Refresh linked tables
' 2.)Set Reference To Microsoft DAO 3.6 Object Library
'Resources
'====================
'DAO Refresh Linked tables -> http://bytes.com/topic/access/answers/635203-how-programmatically-refresh-linked-tables
'
'Date Developer Action
'---------------------------------------------
'02/01/12 ws Created
'02/02/12 ws Added ADO Connection String
'02/02/12 ws Added Debug.Print inside of For Loop
'02/02/12 ws Changed adoTblType from "LINK" to "PASS-THROUGH"
'02/03/12 ws Modified to use DAO instead of ADOX
'02/06/12 ws Added debug.print line
'02/06/12 ws Changed provider from ACE 12 to ACE 14
'02/09/12 ws Added recordcount
'02/09/12 ws Moved debug.print so only linked tables would print
Dim dbe As DAO.DBEngine
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim rst As DAO.Recordset
Dim db As Database
Dim wb As Workbook
Dim ws As Worksheet
Dim strConnect As String
Dim strDbPath As String
Dim strDb As String
Dim strDBFile As String
Dim strOraUID As String
Dim strOraPWD As String
Dim strSQL As String
Dim lngRecCount As Long
'Initialize
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.DisplayAlerts = False
End With
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Dash")
With ws
strDbPath = .Range("B4")
strDb = .Range("B5")
strOraUID = .Range("B9")
strOraPWD = .Range("B10")
End With
If Right$(strDbPath, 1) <> "\" Then strDbPath = strDbPath & _
"\"
strDBFile = strDbPath & strDb
'DAO Connection object
Set dbe = New DAO.DBEngine
Set dbs = dbe.OpenDatabase(strDbPath & strDb)
'Connection String
' strConnect = _
' "Provider=Microsoft.ACE.OLEDB.12.0;" & _
' "Data Source=" & strDbPath & strDb & ";" & _
' "UID=" & strOraUID & ";" & _
' "PWD=" & strOraPWD
strConnect = "Provider=OraOLEDB.Oracle;" & _
"Data Source=(DESCRIPTION=(CID=myCID)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHost)(PORT=1521)))(CONNECT_DATA=(SID=mySID)(SERVER=SHARED)));" & _
"User Id=" & strOraUID & ";" & _
"Password=" & strOraPWD
For Each tdf In dbs.TableDefs
Debug.Print tdf.Name & " " & tdf.Attributes & " " & tdf.LastUpdated
If tdf.Attributes = "536870912" Then
' If InStr(1, tdf.Connect, strDb) > 0 Then
With tdf
.Connect = strConnect
.RefreshLink
strSQL = "SELECT * FROM " & tdf.Name
Set rst = tdf.OpenRecordset(strSQL)
lngRecCount = rst.RecordCount
Debug.Print .Name & " " & .Attributes & " " & .LastUpdated & " Records:" & lngRecCount
End With
End If
Next
'Tidy up
On Error Resume Next
dbs.Close
rst.Close
Set dbs = Nothing
Set dbe = Nothing
Set tdf = Nothing
Set rst = Nothing
Set wb = Nothing
Set ws = Nothing
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.DisplayAlerts = False
End With
End Sub