我有一个表单,它有 2 个文本框和 1 个按钮。文本框是日期从和日期到。单击该按钮时,会运行一些 VBA 代码,该代码会循环查询结果 (qryInvoicesBetweenDates),获取发票 ID 并生成发票的打印预览。问题是,我无法弄清楚如何在循环中将当前 ID 传递给报告。我只需要给 DoCmd.OpenReport 他 invoice_number 变量。
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
非常感谢。