Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access VBA --> ODBC --> Oracle

Posted on 2006-06-14
2
Medium Priority
?
1,814 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 500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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