Too Few Parameters: Expected 1 - MSAcces Error 3061

I'm getting the error 3061 in Access (VBA). Can you help me out? It looks to me like I wrote the select correctly. I know this question has been asked many times here, but I've tried out almost all the answer given but I couldn't resolve my problem. That's why I'm asking for help.

Private Sub cmdPLCompleto_Click()
On Error GoTo cmdPLCompleto_Click_Err

    Dim d As DAO.Database
    Dim r As DAO.Recordset
    Dim strSQL2 As String

    Set d = CurrentDb()


        strSQL2 = "SELECT DISTINCT qryPLCARTASCompleto.ZDR FROM qryPLCARTASCompleto"

    Set r = d.OpenRecordset(strSQL2)

     If r.EOF Then
        MsgBox "The Recordset is empty."
    End If

UPDATE

Here it's the SQL from qryPLCARTASCompleto:

SELECT PLCARTAS.*, Mid([ICP ID],3,4) AS ZDR
FROM PLCARTAS
WHERE (((PLCARTAS.FECHA)=[Forms]![frmCartas]![txtFecha]));

Upvotes: 0

Views: 1799

Answers (1)

Gustav
Gustav

Reputation: 55831

Either ZDR isn't a field name, or your query refers to a field on a form.

If the last, you must specify that parameter before opening the recordset.

For example:

Dim d As DAO.Database
Dim q As DAO.Querydef
Dim r As DAO.Recordset
Dim strSQL2 As String

strSQL2 = "SELECT DISTINCT ZDR FROM qryPLCARTASCompleto"    

Set d = CurrentDb
Set q = d.Querydefs("", strSQL2)
q.Parameters(0).Value = [Forms]![frmCartas]![txtFecha]    

Set r = q.OpenRecordset()

If r.EOF Then
    MsgBox "The Recordset is empty."
End If

Upvotes: 2

Related Questions