I use some code (below) that I found on this site to establish and refresh an ODBC connection to Oracle server/tables. And it works great.
The problem I have is that I need to connect to two different Oracle servers using different login ID's.
Using the information below I login to the FINANCE server and access any information.
UID = myId
PWD = myPwd
ODBCtable = apps_Ap_table
LocalTable = apps_Ap_table
DSN = Oracle
DBQ = FINANCE
And:
UID = MFG_ID
PWD = password
ODBCtable = PO_Items
LocalTable = PO_Items
DSN = Oracle
DBQ = MFG
When I try to access the MFG server/tables I get the following message:
After I use the code to refresh the tables/password of either server for the first time and then try link to the other sever, I get the below error message:
"Microsoft Jet database could not find the object"
"Make sure the object exists and that you spell its name and path correctly."
The only way I have found around this is to completely exit Access and reopen the database and I can then login into the second server.
Can someone help me?
Thanks,
JW
The problem I have is that I need to connect to two different Oracle servers using different login ID's.
Using the information below I login to the FINANCE server and access any information.
UID = myId
PWD = myPwd
ODBCtable = apps_Ap_table
LocalTable = apps_Ap_table
DSN = Oracle
DBQ = FINANCE
And:
UID = MFG_ID
PWD = password
ODBCtable = PO_Items
LocalTable = PO_Items
DSN = Oracle
DBQ = MFG
When I try to access the MFG server/tables I get the following message:
After I use the code to refresh the tables/password of either server for the first time and then try link to the other sever, I get the below error message:
"Microsoft Jet database could not find the object"
"Make sure the object exists and that you spell its name and path correctly."
The only way I have found around this is to completely exit Access and reopen the database and I can then login into the second server.
Can someone help me?
Thanks,
JW
Code:
Function CreateODBCLinkedTables(txtTable As String) As Boolean
On Error GoTo CreateODBCLinkedTables_Err
Dim strTblName As String, strConn As String, strODBCtable As String
Dim db As DAO.Database, rs As DAO.Recordset, tbl As DAO.TableDef
Dim strDSN As String
Dim I As Integer
Dim RefreshLink As Boolean
' ---------------------------------------------
' Register ODBC database(s).
' ---------------------------------------------
RefreshLink = False
Set db = CurrentDb
Set rs = db.OpenRecordset("Select * From " & txtTable & " Order By DSN,ODBCTableName;")
For I = 0 To rs.Fields.Count - 1
If rs(I).Name = "Refresh" Then RefreshLink = True
Next
With rs
While Not .EOF
If RefreshLink = True Then If rs!Refresh = False Then GoTo NextRecord
strDSN = rs("DSN")
' ---------------------------------------------
' Link table.
' ---------------------------------------------
strTblName = rs("LocalTableName")
strConn = "ODBC;"
strConn = strConn & "DSN=" & rs("DSN") & ";"
strConn = strConn & "DBQ=" & rs("DBQ") & ";"
strConn = strConn & "DATABASE=" & rs("DataBase") & ";"
strConn = strConn & "UID=" & rs("UID") & ";"
strConn = strConn & "PWD=" & rs("PWD") & ";"
strConn = strConn & "ASY=" & rs("ASY") & ";"
strConn = strConn & "TABLE=" & rs("ODBCTableName")
If (DoesTblExist(strTblName) = False) Then
Set tbl = db.CreateTableDef(strTblName, _
dbAttachSavePWD, rs("ODBCTableName"), _
strConn)
db.TableDefs.Append tbl
Else
Set tbl = db.TableDefs(strTblName)
tbl.Connect = strConn
tbl.RefreshLink
End If
NextRecord:
rs.MoveNext
Wend
End With
CreateODBCLinkedTables = True
CreateODBCLinkedTables_End:
Set tbl = Nothing
Set rs = Nothing
Set db = Nothing
Exit Function
CreateODBCLinkedTables_Err:
If Err.Number = 13 Then Err.Clear
MsgBox Err.Description, vbCritical, "MyApp"
Resume Next
End Function