I am trying to call a SQL Server procedure to validate user from a function in VBA.
Please see the code below:
proc_validate_user accepts userId and password as input parameters and returns a bit value of 0 or 1
function to call this proc is as under:
Public Function ExecUDF(userId As Integer, pwd As String)
Dim cmd As DAO.Command
Dim par As DAO.Parameter
Dim ret As Variant
Set cmd = New DAO.Command
cmd.ActiveConnection = CurrentDb.Connection
cmd.CommandText = "proc_validate_user"
cmd.CommandType = adCmdStoredProc
'Define the input and output variables and append them to the collection
Set par = cmd.CreateParameter("@userID")
cmd.Parameters.Append par
Set par = cmd.CreateParameter("@pwd")
cmd.Parameters.Append par
Set par = cmd.CreateParameter("@isValid", adParamOutput)
cmd.Parameters.Append par
cmd.Parameters("@userID") = userId
cmd.Parameters("@pwd") = pwd
cmd.Execute
'and then assign the stored procedure return value to the access variable
ret = cmd.Parameters("@isValid").Value
End Function
I am getting an compilation error saying User defined type not defined at "Dim cmd As DAO.Command"
DAO? || you have a typo and aren't closing your function.DAO.Commandis.DAO.Commandnot being defined?