Access FindFirst / FindNext返回此类对象不支持操作

时间:2015-07-22 16:37:34

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

我有这段代码:

Sub printPdfPagesTest(formName As String, fileName As String)
''print each record into a separate pdf file, named according to invoice number

    Dim rs As Recordset
    Dim whereCondition As String
    Dim saveName As String

    Dim strtemp2 As Long
    strtemp2 = 2281821648

    Set rs = CurrentDb.OpenRecordset(fileName)   ''can also pass SQL in as a String

    ''add msgbox: create a number for input invoiceNumber
    ''get value from invoiceNumber  = inputbox ("enter starting invoice num"...)
    ''get value from end invoiceNumber = inputbox("enter ending invoice num"...)
    ''get a start value for the starting location (findRecord) -----need to plan this step out.
    ''add an if statement in do while loop. if where condition is not the end invoice number, keep going

    rs.FindNext "[invoiceNumber]=" & strtemp2

    DoCmd.Close acForm, formName
    rs.Close
    Set rs = Nothing
End Sub

我想要的是在表格中找到strtemp2发票号码的位置,并使用记录上的moveNextmovePrevious来浏览表格。

我不断收到错误消息:

  

此类对象不支持操作。

这就发生在这一行:

Set rs = CurrentDb.OpenRecordset(fileName)  

我尝试将rs更改为:

Dim rs as Recordset

然而它仍然给我同样的错误。

1 个答案:

答案 0 :(得分:0)

您无法从文件名中打开RecordSet。首先打开数据库,然后打开记录集。