I have an excel sheet that connects to a SQL database and runs a stored procedure. I am trying to add one or more parameters to it so it will pull a certain register and group.What is in bold is what i tried for the first parameter. But it doesn't work. I would like a box to popup to enter the RegisterName. Thanks in advance
Sub Importdata()
On Error GoTo Err:
Dim strSQL, sqltest As String
strSQL = "exec RegisterExtractByName WHERE (RegisterName = ?)"
Set param1 = qt.Parameters.Add("RegisterName Parameter", _
xlParamTypeVarChar)
param1.SetParam xlConstant, "First Aide Kit"
If strSQL = "" Then
Exit Sub
End If
Dim cn As ADODB.Connection
Dim lngRecsAff As Long
Set cn = New ADODB.Connection
cn.CommandTimeout = 0 'to fix query timeout issue
cn.Open "Provider=SQLNCLI11;Data Source=" & Range("A1").Value & ";" & _
"Initial Catalog=" & Range("A2").Value & ";User ID=SA;Password=Colorblue!"
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = cn
.Open strSQL
End With
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "MMR"
Dim fieldCount
Dim position
For Each fld In rs.Fields
fieldCount = fieldCount + 1
Sheets(Sheets.Count).Cells(1, fieldCount).Value = fld.Name
Next
Sheets(Sheets.Count).Range("A2").CopyFromRecordset rs
Sheets(Sheets.Count).Cells.EntireColumn.AutoFit
Sheets(Sheets.Count).Rows("1:1").Font.Bold = True
Exit Sub
Err:
MsgBox (Err.Description)
End Sub