2013-02-18 5 views
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 

많은 감사합니다.

답변

3

당신은 OpenReport이있는 곳 문을 사용할 수 있습니다 :

ID는 Rs!invoice_number에 해당하는 보고서의 필드의 이름입니다
DoCmd.OpenReport stDocName, acPreview,,"ID=" & Rs!invoice_number 

. 위의 예제는 숫자 데이터 유형에 대한 것이므로 텍스트 데이터 유형에 따옴표가 필요합니다.