Hi all, I am dealing with a piece of legacy code in an Excel spreadsheet. The following code has worked successfully for years however we have recently moved to a new SQL server and our stored procedure now requires a parameter.
The code retrieves stored procedure names from the database which it then executes in the loop I need to pass a parameter "@PICUOrg" of type nvarchar(6) to the stored procedure. Additionally I need to pass a null value to this parameter.
I have little to no experience of vb so I would massively appreciate some help with this.
This is the code that has worked fine for years (without the additional needed parameter):
here is my "best" attempt at getting this to work, can anyone see what I am doing wrong?
the error I am getting is:
run-time error '-2147217900 (80040e14)':
Syntax error, permission violation, or other nonspecific error
the debugger says that the "cmd.Execute" is the problem, thanks in advance for any help that you can give
normm
The code retrieves stored procedure names from the database which it then executes in the loop I need to pass a parameter "@PICUOrg" of type nvarchar(6) to the stored procedure. Additionally I need to pass a null value to this parameter.
I have little to no experience of vb so I would massively appreciate some help with this.
This is the code that has worked fine for years (without the additional needed parameter):
Code:
With rstReports
.ActiveConnection = con
.Source = "SELECT * " & _
"FROM nr0810_tblNationalReportTableDefs " & _
"ORDER BY CAST(TableID AS int) DESC;"
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open
End With
Do While Not rstReports.EOF
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = con
.CommandType = adCmdStoredProc
.CommandTimeout = 300
.CommandText = rstReports("StoredProcedure")
End With
Set rst = cmd.Execute
OutputADORecordSetToWorksheet rst, rstReports("Title"), rstReports("TableID"), rstReports("MainGroup"), rstReports("MultipleGroupings"), rstReports("ChartType"), rstReports("ChartTotals")
rst.Close
Set rst = Nothing
Set cmd = Nothing
rstReports.MoveNext
Loop
here is my "best" attempt at getting this to work, can anyone see what I am doing wrong?
Code:
With rstReports
.ActiveConnection = con
.Source = "SELECT top 2 * " & _
"FROM tlkpNationalReportTableDefinitions " & _
"ORDER BY CAST(TableID AS int) asc;"
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open
End With
Do While Not rstReports.EOF
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = con
.CommandType = adCmdStoredProc
.CommandTimeout = 300
.CommandText = rstReports("StoredProcedure")
End With
cmd.Parameters.Append cmd.CreateParameter("@PICUOrg", adVarChar, adParamInput, 50, Null)
Set rst = cmd.Execute
OutputADORecordSetToWorksheet rst, rstReports("Title"), rstReports("TableID"), rstReports("MainGroup"), rstReports("MultipleGroupings"), rstReports("ChartType"), rstReports("ChartTotals")
rst.Close
Set rst = Nothing
Set cmd = Nothing
rstReports.MoveNext
Loop
the error I am getting is:
run-time error '-2147217900 (80040e14)':
Syntax error, permission violation, or other nonspecific error
the debugger says that the "cmd.Execute" is the problem, thanks in advance for any help that you can give
normm