Question : Access front end to Oracle Backup

Hello,

I need to connect my Access front-end to some Oracle 10g tables.  

1st questions:  Can I use a connection string to do this?  I don't want to use a DSN.  

2ns question.  I need to use a generic ODBC driver...  if I can connect to Oracle in the VBA code, use someone supply me with connection string and example ADO connection stuff?

Thanks...

Answer : Access front end to Oracle Backup

You can try this code -- but you may need to tweak the strConn variable to build the connection string for the exact driver that you're going to use.

To use it just call the function, passing in the required parameters.  Also, you may need to have your TNSNAMES.ORA file updated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
Function ConnectOracleTable(strTblName As String, _
                sServer As String, sUID As String, sPWD As String) As Boolean

On Error GoTo Connect_Err

    Dim strConn As String
    Dim db As Database
    Dim tbl As TableDef
    
    Set db = CurrentDb()
        
    strConn = "ODBC;"
    strConn = strConn & "DRIVER={Microsoft ODBC Driver for Oracle};"
    strConn = strConn & "Server=" & sServer & ";"
    strConn = strConn & "UID=" & sUID & ";"
    strConn = strConn & "PWD=" & sPWD & ";"
    
    If (DoesTblExist(strTblName) = False) Then
        Set tbl = db.CreateTableDef(strTblName, _
                      dbAttachSavePWD, strTblName, _
                      strConn)
        db.TableDefs.Append tbl
    Else
        Set tbl = db.TableDefs(strTblName)
        tbl.Connect = strConn
        tbl.RefreshLink
    End If
    ConnectOracleTable = True

Connect_Exit:
    Set tbl = Nothing
    Set db = Nothing
    Exit Function

Connect_Err:
    ConnectOracleTable = False
    MsgBox Err & " - " & Error & vbCrLf & "Table attach failed."
    Resume Connect_Exit
    
End Function

'***************************************************************
'The DoesTblExist function validates the existence of a TableDef
'object in the current database. The result determines if an
'object should be appended or its Connect property refreshed.
'***************************************************************

Function DoesTblExist(strTblName As String) As Boolean
   On Error Resume Next
   Dim db As Database, tbl As TableDef
   Set db = CurrentDb
   Set tbl = db.TableDefs(strTblName)
   If Err.Number = 3265 Then   ' Item not found.
      DoesTblExist = False
      Exit Function
   End If
   DoesTblExist = True
   Set tbl = Nothing
   Set db = Nothing
End Function
Random Solutions  
 
programming4us programming4us