参数太少预期1,使用参数输入时

时间:2017-10-06 15:37:50

标签: sql vba ms-access ms-access-2010 ms-access-2007

Too Few Parameters Expected 1

上出现Set rst = qry.OpenRecordSet错误

我昨晚和今天早上花了很多钱来解决这个问题。我在绝望的帮助下。 查询中的字段名称没有错。 我在运行查询时使用参数来询问输入。但我不认为这是导致这个问题的原因。任何建议都将受到高度赞赏!

SQL:

SELECT Sum(dbo_SO_RecapByProductLineWhse.DollarsSold) AS DollarsSold
FROM dbo_SO_RecapByProductLineWhse
HAVING (((dbo_SO_RecapByProductLineWhse.Period)=[Enter the month in two digits]) AND ((dbo_SO_RecapByProductLineWhse.Year)=[Enter the year in four digits]));

我的整个代码是

Option Compare Database
Option Explicit

Public Function TRANS()

    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook
    Dim xlWS As Excel.Worksheet
    Dim acRng As Variant
    Dim xlRow As Integer

    Dim qry As QueryDef
    Dim rst As Recordset
    Set xlApp = New Excel.Application
    Set xlWB = xlApp.Workbooks.Open("C:\Users\M\Desktop\August 2017.xlsx")
    Set xlWS = xlWB.Worksheets("Totals")

    xlRow = (xlWS.Columns("K").End(xlDown).Row)

    Set qry = CurrentDb.QueryDefs("DollarsSold")
    Set rst = qry.OpenRecordset

    Dim c As Integer
    c = 11   'C is the one that stores column number, in which c=1 means column A, 11 is for column K, 12 for Column L
    xlRow = xlRow + 11

    Do Until rst.EOF
        For Each acRng In rst.Fields
            xlWS.Cells(xlRow, c).Formula = acRng
            c = c + 1
        Next acRng
        xlRow = xlRow + 1
        c = 1
        rst.MoveNext
        If xlRow > 25 Then GoTo rq_Exit
    Loop

rq_Exit:
    rst.Close
    Set rst = Nothing
    Set xlWS = Nothing
    xlWB.Close acSaveYes
    Set xlWB = Nothing
    xlApp.Quit
    Set xlApp = Nothing
    Exit Function

End Function

0 个答案:

没有答案