0
두 개의 텍스트 상자와 1 개의 단추가있는 양식이 있습니다. 텍스트 상자는 Date From 및 Date To입니다. 단추를 클릭하면 쿼리 결과 (qryInvoicesBetweenDates)를 반복하는 VBA 코드가 실행되고 송장 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
많은 감사합니다.