Hello All,
The background to my question:
I have an Excel sheet, an Oracle db, and an Access db. I click a button on the Excel sheet and it connects to the Oracle db and grabs some information and pastes it into specific cells on the sheet. I then manually input additional information to the Excel sheet then click another button that sends all the info off as a single record to my Access db.
The issue:
After the export to Access, some corresponding data in Oracle will change. I would like to bypass the Excel via some code in Access that I can run that will connect directly to the Oracle db and update all of my Access records.
The question:
How do I connect to Oracle from Access, run through every record in my access-table, and update access-table.status with oracle-table.status where access-table.id matches oracle-table.id?
I am including a scaled down template of my Excel code because I would like to stay as consistent with how its written as possible. Thanks in advance for any and all assistance!
The code:
The background to my question:
I have an Excel sheet, an Oracle db, and an Access db. I click a button on the Excel sheet and it connects to the Oracle db and grabs some information and pastes it into specific cells on the sheet. I then manually input additional information to the Excel sheet then click another button that sends all the info off as a single record to my Access db.
The issue:
After the export to Access, some corresponding data in Oracle will change. I would like to bypass the Excel via some code in Access that I can run that will connect directly to the Oracle db and update all of my Access records.
The question:
How do I connect to Oracle from Access, run through every record in my access-table, and update access-table.status with oracle-table.status where access-table.id matches oracle-table.id?
I am including a scaled down template of my Excel code because I would like to stay as consistent with how its written as possible. Thanks in advance for any and all assistance!
The code:
Code:
Private Sub importOra_Click() 'import status from oracle
Dim cnOra As New ADODB.Connection
Dim rsOra As New ADODB.Recordset
Dim connOra As String, ID As String, sql As String
ID = [A1]
connOra = "Connection String"
sql = "SELECT table.status FROM table WHERE table.id='" & ID & "';"
cnOra.Open connOra
' copy status from Oracle to cell A2
rsOra.CursorLoaction = adUseClient
rsOra.Open Source:=sql, ActiveConnection:=cnOra
Sheet1.Range("A2").CopyFromRecordset rsOra
rsOra.Close
Set rsOra = Nothing
cn.Close
Set cn = Nothing
End Sub
Private Sub exportAccess_Click() 'export status to access
Dim cnAccess As New ADODB.Connection
Dim rsAccess As New ADODB.Recordset
Dim connAccess As String, tbl As String, ID As String, sql As String
tbl = "projects"
ID = [A1]
sql = "SELECT * FROM " & tbl & " WHERE " & tbl & ".[id]='" & ID & "';"
cnAccess.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & connAccess
rsAcces.Open sql, cnAccess, adOpenKeyset, adLockOptimistic, adCmdTableDirect
With rsAccess
.AddNew
.Fields("status") = [A2]
.Update
.Close
End With
Set rsAccess = Nothing
cnAccess.Close
Set cnAccess = Nothing
End Sub