0
我有一個表單,其中有2個文本框和1個按鈕。文本框是日期從和日期到。單擊按鈕時,會運行一些VBA代碼,這些代碼循環查詢結果(qryInvoicesBetweenDates),獲取發票ID並生成發票的打印預覽。問題是,我無法解決如何在循環中傳遞當前ID的報告。我只需要爲他的invoice_number變量提供DoCmd.OpenReport。將參數傳遞給DoCmd.OpenReport的Access 2010報告
VBA代碼:
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("qryInvoicesBetweenDates")
Dim rs As DAO.Recordset
qdf.Parameters(0) = tbFrom.Value
qdf.Parameters(1) = tbTo.Value
Set rs = qdf.OpenRecordset()
Do Until rs.EOF = True
' Set the invoice number to the current row
'invoice_number = rs.N
invoice_number = rs.Fields(0).Value
' Preview the invoice
Dim stDocName As String
stDocName = "InvoiceForWork"
DoCmd.OpenReport stDocName, acPreview
Loop
非常感謝。