Option Explicit
Dim strCnn As String
Dim adoConn As ADODB.Connection
Dim adoParams As ADODB.Parameters
Dim adoCommand As ADODB.Command
Private Sub cmdGetVoterDist_Click()
Dim adoRecSet As ADODB.Recordset
Set adoRecSet = GetVoterDist(txtGetVoterParam(0), _
txtGetVoterParam(1), _
txtGetVoterParam(2), _
txtGetVoterParam(3), _
txtGetVoterParam(4))
If Not adoRecSet Is Nothing Then
If adoRecSet.RecordCount > 0 Then
txtWard = adoRecSet.Fields("Ward").Value
txtPrecinct = adoRecSet.Fields("Precinct").Value
txtSubPrecinct = adoRecSet.Fields("Subprecinct").Value
txtStateHouse = adoRecSet.Fields("State_House").Value
txtStateSenate = adoRecSet.Fields("State_Senate").Value
Else
txtWard = ""
txtPrecinct = ""
txtSubPrecinct = ""
txtStateHouse = ""
txtStateSenate = ""
End If
Else
txtWard = ""
txtPrecinct = ""
txtSubPrecinct = ""
txtStateHouse = ""
txtStateSenate = ""
End If
Set adoRecSet = Nothing
End Sub
Public Function GetVoterDist(ByVal StNumber As Integer, _
ByVal StDirPfx As String, _
ByVal StName As String, _
ByVal StNameSfx As String, _
ByVal StDirSfx) As ADODB.Recordset
On Error GoTo Err
Dim adoVoterDist As ADODB.Recordset
Dim adoCmd As ADODB.Command
Dim adoParam As ADODB.Parameter
Set adoCmd = New ADODB.Command
With adoCmd
.CommandType = adCmdStoredProc
.CommandText = "GetVoterDistricts"
'Build parameters collection
Set adoParam = .CreateParameter(Name:="RETURN_VALUE", _
Type:=adInteger, _
Direction:=adParamReturnValue)
.Parameters.Append adoParam
Set adoParam = .CreateParameter(Name:="@Street_Number", _
Type:=adInteger, _
Direction:=adParamInput, _
Value:=StNumber)
.Parameters.Append adoParam
Set adoParam = .CreateParameter(Name:="@Street_Direction_Prefix", _
Type:=adVarChar, _
Direction:=adParamInput, _
Size:=2, _
Value:=StDirPfx)
.Parameters.Append adoParam
Set adoParam = .CreateParameter(Name:="@Street_Name", _
Type:=adVarChar, _
Direction:=adParamInput, _
Size:=30, _
Value:=StName)
.Parameters.Append adoParam
Set adoParam = .CreateParameter(Name:="@Street_Name_Suffix", _
Type:=adVarChar, _
Direction:=adParamInput, _
Size:=4, _
Value:=StNameSfx)
.Parameters.Append adoParam
Set adoParam = .CreateParameter(Name:="@Street_Direction_Suffix", _
Type:=adVarChar, _
Direction:=adParamInput, _
Size:=2, _
Value:=StDirSfx)
.Parameters.Append adoParam
End With
Set adoVoterDist = New ADODB.Recordset
adoVoterDist.CursorLocation = adUseClient
' Define a command object for a stored procedure.
Set adoConn = New ADODB.Connection
strCnn = "Provider=SQLOLEDB.1;=;" & _
"Persist Security Info=True;" & _
"User ID=;" & _
"Password=;" & _
"Initial Catalog=AAUIS;=;" & _
"Data Source=SQL;=;" & _
"Connect Timeout=15"
adoConn.Open strCnn
adoCmd.ActiveConnection = adoConn
Call adoVoterDist.Open(Source:=adoCmd)
Set GetVoterDist = adoVoterDist
Exit Function
Err:
MsgBox Err.Description & vbCrLf & Err.Number
End Function