Solved

Access VBA --> ODBC --> Oracle

Posted on 2006-06-14
2
1,738 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
2 Comments
 
LVL 13

Accepted Solution

by:
TommyTupa earned 125 total points
Comment Utility
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
Comment Utility
Exactly the direction I needed.  Well done!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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 …

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now