Error on Stored Procedure VBA code

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I have the following code which errors as given below.

Calling line is

Call ObtainPremiumSummaryData("3000724", #1/7/2017#, #1/7/2016#)

Public Sub ObtainPremiumSummaryData(strCustNo As String, dteClaimYearStart As Date, dtePreviousYearStart As Date)

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim ConnectionString As String

ConnectionString = "Provider=SQLOLEDB;Data Source=HSFSQL01;Initial Catalog=WASP;User ID=HSFS_User; Password=1QAZ2WSX3EDC;Application Name=CRMIFrame Service Live;"

With cnn
.Open ConnectionString
.CommandTimeout = 900
End With

Set cmd = New ADODB.Command

With cmd
.CommandText = "PrUn_PremiumSummary"
.CommandType = adCmdStoredProc
.ActiveConnection = cnn
Set prm = .CreateParameter("CustNo", adVarChar, adParamInput, 30, strCustNo)
.Parameters.Append prm
Set prm = .CreateParameter("ClaimYearStartDate", adDate, adParamInput, 30, dteClaimYearStart)
.Parameters.Append prm
Set prm = .CreateParameter("PreviousYearStartDate", adDate, adParamInput, 30, dtePreviousYearStart)
.Parameters.Append prm
rst.CursorLocation = adUseClient
Set rst = .Execute
End With

‘Error = Object is not allowed when the object is closed.
'I get the same error if I use integers as arguments.
Sheets("Premium Summary Export").Range("A2").CopyFromRecordset rst

cnn.Close

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top