azizrasul
Well-known Member
- Joined
- Jul 7, 2003
- Messages
- 1,304
- Office Version
- 365
- 2019
- 2016
- Platform
- 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
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