Solved

Access VBA --> ODBC --> Oracle

Posted on 2006-06-14
2
1,772 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

752 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