Link to home
Create AccountLog in
Avatar of kshireesh
kshireesh

asked on

Export the recordset to excel from VB

Hi
    I am using a stored procedure and the setting it equal to a record set. How do i see and export the data to excel via excel object in VB6.


Set cmd = New Command
        cmd.ActiveConnection = con
        cmd.CommandType = adCmdStoredProc
        cmd.CommandText = "PlanActalData"
        cmd.Parameters.Append cmd.CreateParameter("ReportReleaseID", adVarChar, adParamInput, 255, cboReportRelease.Text)
        cmd.Parameters.Append cmd.CreateParameter("ReportCycleID", adVarChar, adParamInput, 255, cboReportTestCycle.Text)
        cmd.Parameters.Append cmd.CreateParameter("ReportBuildID", adVarChar, adParamInput, 255, cboReportBuild.Text)
        'cmd.Parameters.Append cmd.CreateParameter("result", adInteger, adParamOutput)
       ' rsGetActualData.Open cmd, con, adOpenForwardOnly, adLockReadOnly
        'cmd.Execute
        'rsGetActualData.Open cmd.Execute, con, adOpenDynamic, adLockReadOnly
        Dim rsCount As Integer
    'MsgBox rsCount
         Set rsGetActualData = cmd.Execute(ra)
ASKER CERTIFIED SOLUTION
Avatar of nds_rahulmistry
nds_rahulmistry

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of kshireesh
kshireesh

ASKER

the fuction does not seems to be working .

thats how i making a function call

 Call ExportToExcel(rsGetActualData).

the error is
3704: Object is not allowed when the object is closed.

i still beleive the anomaly is at Set rsGetActualData = cmd.Execute(ra)
ra = 2 but rsGetActualData.recordcount throws an error.






The recordset which is passed to the function should be open at the time of function call. I have tried to execute the function and it 100000 % working dear...!   I am using the same function for all my projects from last 8 years...!

Just make sure the recordset object is not closed. Check your cursor type also.... ( client side or server side )  Make necessary changes , and you will definitely get the data in Excel.

RAHUL
Confirmed. This code works perfectly.
Don't forget to add the reference to Excel.