Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Oracle Sequence Jumps by 3 from Excel

Hello,
Created an Oracle sequence to give me the next number, however, if i
run the command from my Oracle SQL it works fine, but if i run from
Excel it adds three to the next number. It keeps jumping by threes?

Here's all the code Oracle and Excel.

Oracle Sequence: done to create the Oracle sequence, run only 1 time.
Create sequence BRP_NextNum
start with 9900
increment by 1
nomaxvalue
minvalue 9900
nocycle
cache 50
noorder

Oracle SQL for nextval: Select BRP_NEXTNUM.NEXTVAL FROM DUAL; (this
works from My SQL Program!)

Excel Code: - this jumps the number by 3
Sheets("Sheet1").Select
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim Kolum As Integer 'for entering headers
' Open the connection
cnn.Open "Driver={Microsoft ODBC for Oracle};" & _
"Server=****;" & _
"Uid=****;" & _
"Pwd=****;"

rst.Open _
"select BRP_NEXTNUM.NEXTVAL FROM DUAL ", _
cnn, adOpenKeyset

For Kolum = 0 To rst.Fields.Count - 1 'enter field headers
Cells(1, Kolum + 1) = rst.Fields(Kolum).Name
Next
Cells(2, 1).CopyFromRecordset rst 'dump the result to the sheet
'close the connection
rst.Close

thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Oracle Sequence Jumps by 3 from Excel

change the odbc drive to just the Oracle drive.
then use this code

Dim adoCN As Object
Dim adoRS As Object
Dim rngCell As Range
Dim lngX As Long


Set adoCN = VBA.CreateObject("ADODB.Connection")
adoCN.CursorLocation = 3
adoCN.ConnectionString = "PROVIDER=MSDASQL.1;DRIVER={ORACLE ODBC
DRIVER};SERVER=***;DBQ=***;UID=***;PWD=***;"
adoCN.CommandTimeout = 0 'NO TIMEOUT
adoCN.Open
Set adoRS = VBA.CreateObject("ADODB.Recordset")
adoRS.MaxRecords = 0 '0 = ALL RECORDS
Set adoRS = adoCN.Execute("select BRP_NEXTNUM.NEXTVAL FROM DUAL")

For lngX = 1 To adoRS.Fields.Count
ActiveCell.Offset(0, lngX - 1).Value = adoRS.Fields(lngX - 1).Name
Next lngX
ActiveCell.Offset(1, 0).Select

ActiveCell.CopyFromRecordset adoRS
adoRS.Close
Set adoRS = Nothing

works great Ron.
thanks for all your help!


wrote:
Hello,
Created an Oracle sequence to give me the next number, however, if i
run the command from my Oracle SQL it works fine, but if i run from
Excel it adds three to the next number. It keeps jumping by threes?

Here's all the code Oracle and Excel.

Oracle Sequence: done to create the Oracle sequence, run only 1 time.
Create sequence BRP_NextNum
start with 9900
increment by 1
nomaxvalue
minvalue 9900
nocycle
cache 50
noorder

Oracle SQL for nextval: Select BRP_NEXTNUM.NEXTVAL FROM DUAL; (this
works from My SQL Program!)

Excel Code: - this jumps the number by 3
Sheets("Sheet1").Select
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim Kolum As Integer 'for entering headers
' Open the connection
cnn.Open "Driver={Microsoft ODBC for Oracle};" & _
"Server=****;" & _
"Uid=****;" & _
"Pwd=****;"

rst.Open _
"select BRP_NEXTNUM.NEXTVAL FROM DUAL ", _
cnn, adOpenKeyset

For Kolum = 0 To rst.Fields.Count - 1 'enter field headers
Cells(1, Kolum + 1) = rst.Fields(Kolum).Name
Next
Cells(2, 1).CopyFromRecordset rst 'dump the result to the sheet
'close the connection
rst.Close

thanks.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scroll bar jumps 587 rows Excel 2007 Eef Houniet[_2_] New Users to Excel 2 December 5th 13 11:17 PM
tab key in Excel jumps cursor cells TennisFan63 Excel Worksheet Functions 4 August 9th 08 08:34 PM
When I tab in Excel, it jumps from column A to R. Why? turnfrem Excel Discussion (Misc queries) 2 March 9th 06 11:29 PM
When I doubleclick in Excel, page jumps down/up. EsaMake Excel Discussion (Misc queries) 2 February 1st 06 07:03 PM
Connect to Oracle using Microsoft ODBC for Oracle Kent Excel Programming 2 January 18th 06 03:53 AM


All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"