Random bit of code doubt

nfk

Registered User.
Local time
Today, 14:35
Joined
Sep 11, 2014
Messages
118
Im working with someone else's nightmare and I been seeing a lot of this around...

Code:
Function FunctionName(Year As String, Week As Long, Person As Long) As Boolean

On Error GoTo Error_Handler

Dim cmdSelect As ADODB.Command
Set cmdSelect = New ADODB.Command
Dim prm As ADODB.Parameter
With cmdSelect
    Set .ActiveConnection = CurrentProject.Connection
    .CommandType = adCmdStoredProc
    .CommandText = "dbo.xsp_whatever"
    Set prm = .CreateParameter("@Year", adVarChar, adParamInput, Len(Year))
    prm.Value = Year
    .Parameters.Append prm
    Set prm = .CreateParameter("@Week", adInteger, adParamInput, 4)
    prm.Value = Week
    .Parameters.Append prm
    Set prm = .CreateParameter("@Person", adInteger, adParamInput, 4)
    prm.Value = Person
    .Parameters.Append prm
    Set prm = .CreateParameter("@Paid", adBoolean, adParamOutput, 1)
    .Parameters.Append prm

    .Execute
    If .Parameters("@Paid").Value Then
        FunctionName = True
    Else
        FunctionName = False
    End If
End With
Set prm = Nothing
Set cmdSelect = Nothing
Exit Function
Error_Handler:
Set cmdSelect = Nothing
FunctionName = True
End Function


Now I see that in some cases this critter used this to append data... but, is that the real purpose of such bit of code?, what else can be accomplished? if anything.

Thanks.
 
It appears to be running a stored procedure on SQL Server, though the connection confuses the issue (perhaps it's an adp?). If so, stored procedures are very powerful, and this could do anything that can be done with one: add, edit, delete, etc.
 
But there are some clues, like input parameters or Year, Week, and Person, and a boolean output of Paid. My bet is this function checks if a person was paid in a particular week.
 

Users who are viewing this thread

Back
Top Bottom