Using SQL Server 2012 \ Excel 2010. Excel calls a SQL SP that will return either a 1 or 2 and I then need to perform something else based on that.
Dim con As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.RecordSet
Dim WSP1 As Worksheet
Set con = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.RecordSet
' Log into our SQL Server, and run the Stored Procedure
con.Open "Provider=SQLOLEDB;Data Source=xxxxxxxx;Initial Catalog=xxxxxxx;Integrated Security=SSPI;Trusted_Connection=Yes;"
cmd.ActiveConnection = con
' Set up the parameter for our Stored Procedure
' (Parameter types can be adVarChar,adDate,adInteger)
cmd.Parameters.Append cmd.CreateParameter("User", adVarChar, adParamInput, 15, Trim(Range("C7").Text))
Application.StatusBar = "Running stored procedure..."
cmd.CommandText = "usp_GL_Code_Access"
Set rs = cmd.Execute(, , adCmdStoredProc)
If rs = 1 Then
MsgBox "true"
Else
MsgBox "false"
rs.Close
Set rs = Nothing
Set cmd = Nothing
con.Close
Set con = Nothing
At the moment I'm just using the msgbox true\false to see the value from the rs\SQL SP, but I keep receiving the error message 'Type Mismatch' and it highlights the
IF rs = 1 Then
Line.
Any ideas?