'Argument not recognized when input

I run into

run-time error 1004

Works if I use the cell as an argument but I don't want to constrain to one cell.

I can get this to run if I use an input parameter, but I can't get it to work as an event.

Sub fetchAccountInfo(accountId As Double)

    Dim con As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rs As ADODB.Recordset

    Set con = New ADODB.Connection
    
    con.Open "I put my database here"
    
    Set cmd = New ADODB.Command
    
    cmd.ActiveConnection = con
    cmd.CommandType = adCmdText

    cmd.CommandText = "select a.account_id, a.capacity, a.annual_usage, atm.* " & _
        "from cds_ops..account_transmission atm " & _
        "join cds..account a on atm.account_id = a.account_id " & _
        "where a.account_id=?"
    
    Set rs = cmd.Execute(Parameters:=Accounts.Range(accountId).Value)
    
    writeResultsToSheet rs
    
End Sub

This next sub is in the correct sheet module

Option Explicit

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim id As Double
Dim cellrow As Double

If Intersect(Target, Range("B4:B65536")) Is Nothing Then

Else
    cellrow = Target.Row

    id = Sheets("Accounts").Cells(cellrow, 2)
    Sheets("Accounts").Range("F4:P1000").ClearContents
    Call fetchAccountInfo(id)

End If
End Sub


Solution 1:[1]

Option Explicit

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim id As Double
    If Not Intersect(Target, Range("B4:B65536")) Is Nothing Then
        id = Sheets("Accounts").Cells(Target.Row, "B")
        Call fetchAccountInfo(id)
    End If
End Sub

Sub fetchAccountInfo(accountId As Double)

    Const SQL = " SELECT a.account_id, a.capacity, a.annual_usage, atm.*" & _
                " FROM [cds_ops..account_transmission] atm" & _
                " JOIN [cds..account] a ON atm.account_id = a.account_id" & _
                " WHERE a.account_id=?"

    Dim con As ADODB.Connection, cmd As ADODB.Command, rs As ADODB.Recordset

    Set con = New ADODB.Connection
    con.Open "I put my database here"
    
    Set cmd = New ADODB.Command
    With cmd
        .ActiveConnection = con
        .CommandType = adCmdText
        .CommandText = SQL
        .Parameters.Append .CreateParameter("ID", adDouble, adParamInput)
        Set rs = .Execute(, accountId)
    End With
    
    With Sheets("Accounts")
        .Range("F4:P1000").ClearContents
        .Range("F4").CopyFromRecordset rs
    End With
End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CDP1802