Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 7th, 2004, 08:48 AM
Authorized User
 
Join Date: Sep 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access VBA with Oracle connection

Hi everyone,

I am using Access as an interface to an SQL Server database and an Oracle database.

What I do is I insert a new record in an ADODB recordset. Here is how I do it in SQL server:

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("select * from EAM_T where EAMID=someNum, dbOpenDynaset, dbSeeChanges)
Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset

rs2.Open "Select * from EAM_T", CurrentProject.Connection, adOpenKeyset, adLockOptimistic

rs2.AddNew
rs2![Name] = rs![Name]
rs2.Update
newID = rs2!EAMlID
rs2.Close

This always works fine in SQL server. Upon browsing a lot of documentation I found that you have to use Requery in Oracle for this to work. So, here is how I do it in Oracle:

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("select * from EAM_T where EAMID=someNum, dbOpenDynaset, dbSeeChanges)
Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset

rs2.Open "Select * from EAM_T", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs2.AddNew
rs2![Name] = rs![Name]
rs2.Update
bookmark = rs2.AbsolutePosition
rs2.Requery
rs2.AbsolutePosition = bookmark
newID = rs2!EAMID

This works most of the time. But sometimes it returns another ID, not the one that just existed. So, the newID is inserted in some position that is not the same after the requery. How can I make sure that the new record is always inserted at the end and this requery works fine. Basically, all I am trying to so is get the field value of a newly inserted row in Oracle.

Thanks,

Pankaj







Similar Threads
Thread Thread Starter Forum Replies Last Post
Oracle Connection teddyk ASP.NET 2.0 Basics 1 October 6th, 2008 06:08 PM
oracle connection silvia C# 4 January 17th, 2006 08:12 AM
Connection between Access XP and Oracle Tachyophan Access 1 February 14th, 2005 10:45 AM
Begging Access 2003 VBA Ch 5 - connection problem Quixote BOOK: Beginning Access VBA 2 February 3rd, 2005 06:45 PM
Access VBA problem with Oracle database pankaj_daga Oracle 0 September 7th, 2004 08:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.