Ms-access – run time error “3061” : too few parameters, expected 1

ms-accessms-access-2007

VB6 (32 BIT – 1998) ERROR 3061 – WINDOWS 7 – ACCESS 2007 – EXCEL 2007

I wrote a VB6 program that extracts records from an ACCESS 2007 database and writes them into an EXCEL 2007 sheet.

The program worked fine and I used the exe for several months. Then, mayhem happended.
A new 1GB HD I installed as "C" commited suicide and developed a permanent error.
My secondary 2 GB "D" also developed a simultaneous permanent error.
Bye bye system.

I was able to recover everything. Put in new hard driveS (warranty provided them). Reinstalled W7, ACCESS 2007, EXCEL 2007 and VB6, all from CD.

Now, when I run my VB exe, gives me runtime error 3061 – too few parameters – at least 1 was expected.

The culprit is the select:

Set rs = db.OpenRecordset(Select_str)

THE SELECT CONTAINS:

SELECT
    HORA,
    ARL,
    ARL_ECON,
    ESTADO_OPE,
    EST_REMUN,
    ENERGIA,
    POT_DISP,
    POT_RECORTADA,
    PIND,
    PINDFORZ,
    CGN,
    CGO,
    CFO,
    CCM,
    PRECIO_NODO,
    PR_REM_ENERGIA,
    SCTD,
    SCO,
    COSTO_406,
    COMPRA_SPOT,
    POT_DISP_RESERVA,
    POT_DISP_GAS,
    GAS_NOMINADO,
    REM_ADICIONAL,
    REM_ADIC_TOTAL,
    DESP_ECON,
    PGENE_COMP_446,
    REM_ADIC_COMP_446,
    REM_GAS_6866,
    REMUN_ADIC_6866,
    POT_DISP_ACD
FROM VALORES_GENERADORES
WHERE GRUPO = "XXXXXX"

I build the select this way:

BeguinSelectString$ = "SELECT HORA, "
DE$ = " FROM "
Donde$ = " WHERE GRUPO = " + Chr(34)
FinDelSelect$ = Chr(34) + " "

Select_str = ""

' I BUILD THIS SELECT WITH A FOR/NEXT TO LIST ALL FIELDS AND PUT THEM IN THE SELECT.

Select_str = BeguinSelectString$

For i = 0 To (Max_Index_de_Records_1 - 1)

    Select_str = Select_str + Nombres_de_Campos_1(i) + ", "

Next i

    Select_str = Select_str + Nombres_de_Campos_1(Max_Index_de_Records_1) ' I INSERT THE LAST FIELD WITHOUT THE COMMA, ELSE IT GIVES AN ERROR

    Select_str = Select_str + _
             DE$ + _
             Tabla + _
             Donde$ + _
             sNombre_del_Grupo + _
             FinDelSelect$

THE PROJECT REFERENCES ARE, in this order:

  1. Visual Basic for Applications
  2. Visual Basic runtime objects and procedures
  3. Visual Basic objects and procedures
  4. ActiveBar control
  5. ActiveEx type library
  6. Microsoft DAO 3.6 Object Library
  7. Microsoft Excel 12.0 Object Library
  8. Microsoft Access 12.0 Object Library
  9. Microsoft Office 12.0 Object Library

Best Answer

If you're certain the SELECT statement in your question is the exact statement built by your code, copy that text, create a new query in the Access query designer, switch to SQL View, paste in the copied text and try to run it.

Access will present a parameter input box asking you to supply a value for the parameter. Notice that box includes the "name" of whatever Access thinks is the parameter. That parameter name is something (often a misspelled field name) Access can't find in the VALORES_GENERADORES table. Since it can't find the name, it assumes the name must be a parameter.

Related Topic