run time error “3061” : too few parameters, expected 1

◇◆丶佛笑我妖孽 提交于 2019-12-02 08:44:39

问题


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

回答1:


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.




回答2:


THANK YOU, HANSUP, YOUR SUGGESTION SOLVED THE PROBLEM!!!

This is a set of daily databases provided to me by a third party. The database structure and the table fields have not changed in the last years. Furthermome, my program worked fine extracting daily info for almost a year!! Then, at the same time my PC commited suicide, the database designer decided to CHANGE THE NAME OF THE LAST FIELD IN THE TABLE I QUERY. Hi did this wierd thing in the midlle of a month (@#!##!!!). When I checked the field names of the table, I looked at the day 1 database table, which still had the old name!!! So, I thougth my re-installing everything was the culprit.

Now I changed the field name (it was not a misspelling or syntax error) and everything is back to normal again.

Thanks again!!!

Rudy



来源:https://stackoverflow.com/questions/18042999/run-time-error-3061-too-few-parameters-expected-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!