Public Function AddNote(user As String, Assignee As String, NoteTitle As Long, Notes As String) As Boolean
Dim cmd As ADODB.Command
Dim retlng As ADODB.Parameter
'Create command Object
Set cmd = New ADODB.Command
'Create parameter
Set retlng = New ADODB.Parameter
With cmd
'Set the command type to Stored Procedure
.CommandType = adCmdStoredProc
' The name of the stored proc, in sql server would look something like
' usp_InsertNoteGeneric(123,456789,'B7534845','B7534845','Adding a new Note',14,'2012/05/01/ 22:00')
.CommandText = "usp_InsertNoteGeneric"
'Set the connection
.ActiveConnection = Mother.Connection.cn
'Create the parameter that will be passed out
With retlng
.Direction = adParamReturnValue 'A return paramter
.Name = "@RETURN_VALUE" 'The name of the paramater in SQL
.Type = adInteger 'The return type
End With
'Here we add the parameters to the command object
.Parameters.Append retlng
'For each paramter we must set it's SQL param name, its Type, Its direction, its size, and value
' command.CreateParameter (Name, Type, Direction, Size, Value)
.Parameters.Append .CreateParameter("@MainTagbRef", adInteger, adParamInput, , Mother.ID)
.Parameters.Append .CreateParameter("@ForceID", adVarChar, adParamInput, 6, Mother.FORCEID)
.Parameters.Append .CreateParameter("@UserID", adVarChar, adParamInput, 50, user)
.Parameters.Append .CreateParameter("@AssignedTo", adVarChar, adParamInput, 50, Assignee)
.Parameters.Append .CreateParameter("@NoteContent", adLongVarChar, adParamInput, 1073741823, Notes)
.Parameters.Append .CreateParameter("@NoteTitle", adInteger, adParamInput, , NoteTitle)
.Parameters.Append .CreateParameter("@DateCreated", adDate, adParamInput, 0, Format(Now(), "yyyy/MM/dd hh:mm:ss"))
End With
'Execute the command
cmd.Execute
'Read the return Value
If retlng.value > 0 Then
AddNote = True
End If
End Function