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
非常感谢。