Solved

Access VBA --> ODBC --> Oracle

Posted on 2006-06-14
2
1,781 Views
Last Modified: 2008-03-10
I previously had an MDB front end connected to an MDB back end.  Using VBA from the front end to open a recordset of a particular table and add records to that table was basically done as follows:

Dim con As ADODB.Connection
Dim rsX As New ADODB.Recordset

Set con = CurrentProject.Connection

rsX.Open "tblX", con, , adLockPessimistic

rsX.AddNew
    rsX!field1 = "xxx"
    rsX!field2 = "yyy"
    rsX!field3 = "zzz"
rsX.Update

Simple.  Worked great.  No problem...  BUT, now the MDB back-end data has been converted to Oracle and I need to change the front-end VBA to accomplish the same logic as above.  I've gotten this far:

Dim con As New ADODB.Connection
con.Open "DRIVER={ORACLE ODBC DRIVER};..." (whole connection string not shown...)

The connection opens fine, but that's where I'm stuck.  How do I open a recordset of the table to which I want to add records?  And then how do I add the records?  Am I going to have to use "INSERT..." SQL to get this done?  I've seen some references to being able to establish a recordset and then manipulate it just as I did above with Access tables, but I haven't gotten it to work...

Thanks for any tips!
0
Comment
Question by:jahooper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
TommyTupa earned 125 total points
ID: 16908571
Check out this great example: http://cis.csuohio.edu/~matos/notes/ist-331/NEW-Oracle-Access-Notes.doc

Also, below is VBA for opening a recordset.  If you need to insert just do a cn.execute MySQLString


Private Sub Form_Open(Cancel As Integer)
   Dim cn As ADODB.Connection
   Dim rs As ADODB.Recordset
         
   'Create a new ADO Connection object
   Set cn = New ADODB.Connection

   With cn
      .Provider = "MSDAORA"
      .Properties("Data Source").Value = "MyOracleServer"
      .Properties("User ID").Value = "username"
      .Properties("Password").Value = "password"          
      .Open
   End With

   'Create an instance of the ADO Recordset class, and
   'set its properties
   Set rs = New ADODB.Recordset
   With rs
      Set .ActiveConnection = cn
      .Source = "SELECT * FROM Customers"
      .LockType = adLockOptimistic
      .CursorType = adOpenKeyset
      .CursorLocation = adUseClient
      .Open
   End With

   'Set the form's Recordset property to the ADO recordset
   Set Me.Recordset = rs
   Set rs = Nothing
   Set cn = Nothing
End Sub
0
 

Author Comment

by:jahooper
ID: 16910824
Exactly the direction I needed.  Well done!
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question