Public Function UpdateEquipmentRecord(strTestType As String, _
intTestSequence As Integer, _
strWSUCode As String, _
decTestValue As Variant, _
decPctChange As Variant, _
StrLocation As Variant, _
StrOperator As Variant) As Integer
On Error GoTo errHandler
Dim oCn As ADODB.Connection
Dim oCmd As ADODB.Command
Dim RecordsAffectedCount As Long
'We probably need no more than Four parameters, but to avoid future refactoring, set up 7
Dim prm0 As New ADODB.Parameter
Dim prm1 As New ADODB.Parameter
Dim prm2 As New ADODB.Parameter
Dim prm3 As New ADODB.Parameter
Dim prm4 As New ADODB.Parameter
Dim prm5 As New ADODB.Parameter
Dim prm6 As New ADODB.Parameter
Dim prm7 As New ADODB.Parameter
Dim paramName As String
Dim paramType As ADODB.DataTypeEnum
Dim paramDirection As ADODB.ParameterDirectionEnum
Dim paramValue As String
Dim ReturnCode As Integer
Set oCn = New ADODB.Connection
oCn.ConnectionString = UTV("strHostConnection") 'stored credentials that connect to the remote SQL Server.
End If
oCn.Open
oCn.CommandTimeout = 0
Set oCmd = New ADODB.Command
oCmd.CommandTimeout = 0
oCmd.CommandType = adCmdStoredProc
oCmd.CommandText = "InsertPerformance" ' This is the name of a Stored Procedure that executes the append of the new values.
oCmd.ActiveConnection = oCn
'prm1
paramName = "@TestSequence "
paramType = adInteger
paramDirection = adParamInput
paramValue = intTestSequence
With prm1
.Name = paramName
.Direction = paramDirection
.Type = paramType
.Value = paramValue
' .Size = 50
End With
oCmd.Parameters(1) = prm1
'prm2
paramName = "@WSUCode"
paramType = adVarChar
paramDirection = adParamInput
paramValue = strWSUCode
With prm2
.Name = paramName
.Direction = paramDirection
.Type = paramType
.Value = paramValue
.Size = 15
End With
oCmd.Parameters(2) = prm2
'prm3
paramName = "@PerformanceValue"
paramType = adDecimal
paramDirection = adParamInput
paramValue = decTestValue
With prm3
.Name = paramName
.Direction = paramDirection
.Type = paramType
.Value = paramValue
End With
oCmd.Parameters(3) = prm3
'prm4
paramName = "@TestType"
paramType = adVarChar
paramDirection = adParamInput
paramValue = strTestType
With prm4
.Name = paramName
.Direction = paramDirection
.Type = paramType
.Value = paramValue
End With
oCmd.Parameters(4) = prm4
'prm5
paramName = "@PercentChange"
paramType = adDecimal
paramDirection = adParamInput
paramValue = decPctChange
With prm5
.Name = paramName
.Direction = paramDirection
.Type = paramType
.Value = paramValue
End With
oCmd.Parameters(5) = prm5
'prm6
paramName = "@PerformanceLocation"
' paramType = adVarChar
paramType = adDecimal
paramDirection = adParamInput
paramValue = StrLocation
With prm6
.Name = paramName
.Direction = paramDirection
.Type = paramType
.Value = paramValue
End With
oCmd.Parameters(6) = prm6
'prm7
paramName = "@Operator"
paramType = adVarChar
paramDirection = adParamInput
paramValue = StrOperator
With prm7
.Name = paramName
.Direction = paramDirection
.Type = paramType
.Value = paramValue
End With
oCmd.Parameters(7) = prm7
'return
With prm0
.Name = "rc"
.Type = adBigInt
.Direction = adParamReturnValue
End With
oCmd.Execute RecordsAffectedCount
ReturnCode = oCmd.Parameters(0)
UpdateEquipmentRecord = ReturnCode
CleanUp:
On Error Resume Next
Set oCmd = Nothing
Set oCn = Nothing
ExitProc:
Exit Function
errHandler:
If Err = -2147217873 Then
MsgBox "That Performance Record has been added for this bat." & vbCrLf & _
"You can adjust Test Results manually on the test Management screen", vbOKOnly, UTV("MBTItleErr") & _
"Can't Reimport Duplicate Performance Result"
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure UpdateEquipmentRecord of Module Module1"
End If
Resume CleanUp
Resume
End Function