LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error Number: 91 object variable or With block Variable not set

Hi,
This code was built to get Data from Database and use the data as a source
for a Chart. I am finding it difficult to get the Range into an variable
where I am getting a Error MEssage as saying as :

<ERROR
Error Number 91
object variable or With block Variable not set
</ERROR

This error prompts once the following code is executed:

<CODE
' Assign the address of the selected range of cells to a variable.
rRange = Selection.Address()
</CODE


The full Code is give below.

<CODE
Private Sub CommandButton1_Click()
On Error GoTo Err_Execute

Dim oCon As ADODB.Connection
Dim oRs As ADODB.Recordset
Dim sSql, sID As String
Dim rRange As Range
Dim i As Integer

'Delete the Previous Request
Range("A9", Range("A9").End(xlToRight)).Select

' Select the current range of data. This line of code assumes that
' the current region of cells is contiguous - without empty rows
' or columns.
Selection.CurrentRegion.Select


' Assign the address of the selected range of cells to a variable.
rRange = Selection.Address()

Selection.Clear

i = 9

If cmbStock.ListIndex 0 Then
sID = Left(cmbStock.Value, 9)
Else
sID = "JKH N0000"
End If

sSql = "SELECT XSACTDATE, EQUITYID, CLOSINGPRICE FROM EQUITYPRICES " & _
"WHERE XSACTDATE = '" & Format(dtpFrom.Value, "DD-MMM-YYYY") &
"' " & _
"AND XSACTDATE <= '" & Format(dtpTo.Value, "DD-MMM-YYYY") & "' "
& _
"AND EQUITYID = '" & sID & "' ORDER BY XSACTDATE ASC"

MsgBox sSql

Set oCon = New ADODB.Connection
Set oRs = New ADODB.Recordset

oRs.CursorLocation = adUseClient

'oCon.Open "DSN=JKSB_BACKEND", "JKSBWEB", "webjksb"
oCon.Open "Provider=MSDAORA.1;Password=mypwd;User ID=myuser;Data
Source=MYORACLE;Persist Security Info=True"
oRs.Open sSql, oCon, adOpenDynamic, adLockOptimistic

If Not oRs.EOF Then
oRs.MoveFirst

While Not oRs.EOF
Cells(i, 1) = oRs.Fields("xsactdate").Value
Cells(i, 2) = oRs.Fields("closingprice").Value

i = i + 1

oRs.MoveNext
Wend
Else
MsgBox "No Records Found!", vbExclamation, "Error"
End If

'Clean up
If Not oRs Is Nothing Then
If oRs.State = adStateOpen Then oRs.Close
End If
Set oRs = Nothing

If Not oCon Is Nothing Then
If oCon.State = adStateOpen Then oCon.Close
End If
Set oCon = Nothing


ActiveChart.SetSourceData (CVar(rRange))

MsgBox "Records Filled: " & CStr(i - 9)


Err_Execute:
MsgBox "Error number: " & Err.Number & vbCr & _
Err.Description
End Sub

</CODE
--
Hifni Shahzard Nazeer M.
 
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
Need help with Error 'object variable or with block variable not set' Francois via OfficeKB.com Excel Programming 5 April 30th 07 03:05 PM
Run-Time error '91': Object variable of With block variable not set jammin1911 Excel Programming 3 June 6th 06 06:36 PM
Getting inconsistent Error 91-Object variable or With block variable not set mfq Excel Programming 0 December 14th 05 06:08 PM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 08:57 PM.

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"