I am attempting to revise a chunk of code that was used to pull reporting from a database and point it to a new report with a different parameter. The code below is very close to accomplishing this. However, there seems to be an issue with either my variable "nEndDate" or the ADODB command. When I run the code I get an error stating that the procedure was not supplied with the expected parameter. The parameter required by the database must be 'datetime' format.

Any suggestions out there?


Global objConnection As clsConnection

Sub cmdGetFinancialPackageData_Click()

    Dim cn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rst As ADODB.Recordset
    Dim wsParameters As Worksheet
    Dim wsData As Worksheet
    Dim nEndDate As date

    Application.ScreenUpdating = False
    Application.Cursor = xlWait
        
    Set wsParameters = ActiveWorkbook.Worksheets("Download FP Data")
    
    Set nEndDate = wsParameters.Range("C5")
    
    Set cn = OpenConnection()
    
    Set cmd = New ADODB.Command

    cmd.ActiveConnection = cn
    cmd.CommandText = "MissedRevenue"
    cmd.CommandType = adCmdStoredProc
    cmd.Parameters.Append cmd.CreateParameter("@EndDate", adDBDate, adParamInput, nEndDate)
    
    cmd.CommandTimeout = 50000
    
    Set rst = cmd.Execute()
    
    If rst.BOF And rst.EOF Then
        MsgBox "Recordset for Financial Package data is empty.", vbExclamation, "Error"
        Exit Sub
    End If
    
    Set wsData = ActiveWorkbook.Worksheets("Financial Package Data")
    wsData.Activate
    Cells.Select
    Selection.ClearContents
    WriteHeaders wsData.Range("A1"), rst
    wsData.Range("A2").CopyFromRecordset rst
   
    rst.Close
    Set rst = Nothing

    cn.Close
    Set cn = Nothing
    RevertCursor
    
Exit_Sub:
    Exit Sub
 
Private Function OpenConnection() As Connection

    Dim cn As New ADODB.Connection
    Dim sConnString As String
    Dim sServer As String
    Dim sDatabase As String
    
    If (objConnection Is Nothing) Then
        Set objConnection = New clsConnection
    End If
    
    'Get connection string info from the "Connection Info" tab
    sServer = objConnection.ServerCell.Value
    sDatabase = objConnection.DatabaseCell.Value
    
    sConnString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
        "Persist Security Info=False;" & _
        "Initial Catalog=" & sDatabase & ";" & _
        "Data Source=" & sServer

    With cn
        .CursorLocation = adUseClient
        .ConnectionTimeout = 30
        .Open sConnString
    End With
    
    Set OpenConnection = cn

Exit_Function:
    Exit Function