Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / February 2006



Tip: Looking for answers? Try searching our database.

excute stored proc in VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
William - 02 Feb 2006 19:36 GMT
Hi,
i think executing the stored proc in VB and VBA are very similar. so, i
posted the question to here to see if someone has came across the same
problem before...

i'm trying to execute a stored proc stored in Sybase in VBA EXCEL 2003. the
stored proc is supposed to return about 30 rows. but, if i execute the stored
proc in VBA, rs.recordcount is -1 and rs.eof is true. i enclosed the stored
proc below. it just makes me very frustrated. any help or feedback is very
welcome.
Thank you very much.
will

   MsgBox rs.RecordCount ==> ALWAYS RETURN -1

       While Not rs.EOF ==> rs.EOF = TRUE

create procedure sp_CoverageEventHorizonHistory
@NoteDBSecId varchar(30)
as

select s.Symbol, s.SecurityName as 'Company', t.PriceTarget_Numeric
from Securities s, TargetPriceActions t
where s.NoteDBSecId =@NoteDBSecId
and s.NoteDBSecId=t.NoteDBSecId and t.PriceTarget_Numeric !=NULL

go

Private Sub CommandButton1_Click()

Dim DB As BSERDBConnect.BSERDataConnect
Dim con As ADODB.Connection
Dim comm As ADODB.Command
Dim rs As ADODB.Recordset

Dim SQL As String

Set DB = New BSERDataConnect
DB.connectDB "database", "login", "pwd"

   Set conn = DB.oConn
   Set comm = New ADODB.Command
   Set rs = New ADODB.Recordset

   comm.ActiveConnection = conn
   comm.CommandType = adCmdStoredProc
   comm.CommandText = "sp_CoverageEventHorizonHistory"
   
 
   Dim paramIn1 As ADODB.Parameter
   
   Set paramIn1 = comm.CreateParameter("NoteDBSecId", adVarChar,
adParamInput, 30, "1782")
   comm.Parameters.Append paramIn1

   Dim records As Integer
   
   rs.CursorLocation = adUseClient
   Set rs = comm.Execute(records)
   
   Set wksEH = Worksheets("TESTING")

   For c = 0 To rs.Fields.Count - 1
       wksEH.Cells(1, c + 1).Value = rs.Fields(c).Name
   Next
   With wksEH.Rows(1).Cells.Font
       .Underline = True
       .Bold = True
   End With

   MsgBox rs.RecordCount ==> ALWAYS RETURN -1
   Do While Not rs Is Nothing
       While Not rs.EOF ==> rs.EOF = TRUE
           MsgBox rs.Fields(0) & " " & rs.Fields(1)
           rs.MoveNext
       Wend
       Set rs = rs.NextRecordset
   Loop

   Set comm = Nothing
   
End Sub

Signature

 

Paul Clement - 03 Feb 2006 16:36 GMT
¤ Hi,
¤ i think executing the stored proc in VB and VBA are very similar. so, i
¤ posted the question to here to see if someone has came across the same
¤ problem before...
¤
¤ i'm trying to execute a stored proc stored in Sybase in VBA EXCEL 2003. the
¤ stored proc is supposed to return about 30 rows. but, if i execute the stored
¤ proc in VBA, rs.recordcount is -1 and rs.eof is true. i enclosed the stored
¤ proc below. it just makes me very frustrated. any help or feedback is very
¤ welcome.

You are correct. If you are using the *exact* same ADO code then the results should be the same.

One thing I did notice is that you are not specifying a cursor type. The default is forward-only, in
which case -1 is always returned as the RecordCount property value - even in VB code.

Paul
~~~~
Microsoft MVP (Visual Basic)
William - 03 Feb 2006 19:33 GMT
i changed the code. and, i get 0 for recordcount.

'old code
'    rs.CursorLocation = adUseClient
'    Set rs = comm.Execute(records)

'new code.  
   With rs
       .CursorLocation = adUseClient
       .CursorType = adOpenDynamic
       .LockType = adLockReadOnly
       .Open comm
   End With

Signature

 

> ¤ Hi,
> ¤ i think executing the stored proc in VB and VBA are very similar. so, i
[quoted text clipped - 15 lines]
> ~~~~
> Microsoft MVP (Visual Basic)
Larb - 05 Feb 2006 09:41 GMT
It can't be done !

simple

call the stored proc as s tring

I have posted many questions on the board regarding the "command"
object

I think we will have to wait until a new version of the ODBC driver
arrives.

So to call your stored proc you will have to do as a string.

example:

Dim sQuery as string

sQuery = "CALL spExample ()"

rs.open squery, MyConn

And yes I agree - give me your way ! syntactically it is much better to
use the command object.

Hope that helps

Peter
Paul Clement - 06 Feb 2006 14:23 GMT
¤ i changed the code. and, i get 0 for recordcount.
¤
¤ 'old code
¤ '    rs.CursorLocation = adUseClient
¤ '    Set rs = comm.Execute(records)
¤  
¤ 'new code.  
¤     With rs
¤         .CursorLocation = adUseClient
¤         .CursorType = adOpenDynamic
¤         .LockType = adLockReadOnly
¤         .Open comm
¤     End With

Is .EOF True?

Paul
~~~~
Microsoft MVP (Visual Basic)
William - 06 Feb 2006 16:31 GMT
yes, rs.EOF is equal to TRUE.

interesing, this portion of the code does return the columns' labels of the
stored proc.

   For c = 0 To rs.Fields.Count - 1
       wksEH.Cells(1, c + 1).Value = rs.Fields(c).Name
   Next

stored proc.
========
create procedure sp_CoverageEventHorizonHistory
@NoteDBSecId varchar(30)
as

select s.Symbol, s.SecurityName as 'Company', t.PriceTarget_Numeric
from Securities s, TargetPriceActions t
where s.NoteDBSecId =@NoteDBSecId
and s.NoteDBSecId=t.NoteDBSecId and t.PriceTarget_Numeric !=NULL

go

so, i think the VBA code does excute the stored proc. but, somehow it
doesn't return correct result set back.

thanks.

Signature

 

> ¤ i changed the code. and, i get 0 for recordcount.
> ¤
[quoted text clipped - 15 lines]
> ~~~~
> Microsoft MVP (Visual Basic)
Paul Clement - 06 Feb 2006 18:56 GMT
¤ yes, rs.EOF is equal to TRUE.
¤
¤ interesing, this portion of the code does return the columns' labels of the
¤ stored proc.
¤
¤     For c = 0 To rs.Fields.Count - 1
¤         wksEH.Cells(1, c + 1).Value = rs.Fields(c).Name
¤     Next
¤
¤ stored proc.
¤ ========
¤ create procedure sp_CoverageEventHorizonHistory
¤ @NoteDBSecId varchar(30)
¤ as
¤
¤ select s.Symbol, s.SecurityName as 'Company', t.PriceTarget_Numeric
¤ from Securities s, TargetPriceActions t
¤ where s.NoteDBSecId =@NoteDBSecId
¤ and s.NoteDBSecId=t.NoteDBSecId and t.PriceTarget_Numeric !=NULL
¤
¤ go
¤
¤ so, i think the VBA code does excute the stored proc. but, somehow it
¤ doesn't return correct result set back.

Does it make any difference if you set the parameter size to the exact size of the value (instead of
a value of 30)?

Paul
~~~~
Microsoft MVP (Visual Basic)
Oleg Neroslavsky - 28 Feb 2006 20:28 GMT
So, what is the end of this story? I ran into the very same problem.
After moving to the Office 2003, within a week I used my old VBA code
successfully, and after some changes on the Sybase side it stopped to
work. I tried all suggestions in this forum and none helped.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.