Yes I have cut of the procedure so the End Select does not show. The form I am working off of has a calendar control I use to pass dates to the code (I have also omitted code where I test the dates for error conditions) a list box (lstSelectClient) and an unbound text box (txtCriteria ) Following is code i use to print a single report
Code:
Sub cmdPrintReport_Click()
On Error GoTo Err_cmdPrintReport_Click
Dim stDocName As String
Dim stDailyReport As String
Dim blnOK As Boolean
Dim intNumberRecords As Integer
If IsNull(BeginningDate) Then
Beep
MsgBox "You Must Select a Beginning Date", _
vbExclamation, conAppName
DoCmd.CancelEvent
SetDate.Caption = "Set Beginning Date"
SelectDate.SetFocus
Exit Sub
End If
If IsNull(EndingDate) Then
Beep
MsgBox "You Must Select an Ending Date", _
vbExclamation, conAppName
DoCmd.CancelEvent
SetDate.Caption = "Set Ending Date"
SelectDate.SetFocus
Exit Sub
End If
If EndingDate < BeginningDate Then
Beep
MsgBox "The Ending Date Must Be Later Than Beginning Date", _
vbExclamation, conAppName
DoCmd.CancelEvent
SetDate.Caption = "Set Ending Date"
SelectDate.SetFocus
Exit Sub
End If
Select Case ogPrintReports
Case Is = 1
If IsNull(lstSelectClient) Then
Beep
MsgBox "You Must Select a Client Name", _
vbExclamation, conAppName
DoCmd.CancelEvent
lstSelectClient.SetFocus
Exit Sub
End If
intNumberRecords = DCount("OrderID", "tblInvoices", _
"[CustomerID] = Form!lstSelectClient And [Date] >= Form!BeginningDate And [Date] <= Form!EndingDate And [Paid] = 0")
If intNumberRecords = 0 Then
Beep
MsgBox "There are no unpaid transactions for " & lstSelectClient, _
vbExclamation, conAppName
Exit Sub
Else
Me.txtCriteria = lstSelectClient
stDocName = "rptStatements"
DoCmd.OpenReport stDocName, acNormal
DoCmd.Maximize
Forms!frmPrintReports.Visible = False
DoCmd.ShowToolbar "tlbrSemimonthly", acToolbarYes
Exit Sub
End If
Case Is = 2
If IsNull(lstSelectClient) Then
Beep
MsgBox "You Must Select a Client Name", _
vbExclamation, conAppName
DoCmd.CancelEvent
lstSelectClient.SetFocus
Exit Sub
End If
stDailyReport = DLookup("[DailyReport]", "[tblCustomers]", _
"[CustomerId] = Form!lstSelectClient")
intNumberRecords = DCount("OrderID", "tblInvoices", _
"[CustomerID] = Form!lstSelectClient And [Date] >= Form!BeginningDate And [Date] <= Form!EndingDate")
If intNumberRecords = 0 Then
Beep
blnOK = Confirm("There were no transactions for this Client. Print AnyWay?")
If blnOK Then
stDocName = "rptSemiMonthly(NoIndTrans)"
DoCmd.OpenReport stDocName, acPreview
Exit Sub
End If
End If
If stDailyReport = "No" Then
Me.txtCriteria = lstSelectClient
stDocName = "rptSemiMonthly"
DoCmd.OpenReport stDocName, acNormal
Exit Sub
Else
Beep
blnOK = Confirm("This Client Doesn't usually get Semi Monthly Report. Print AnyWay?")
If blnOK Then
Me.txtCriteria = lstSelectClient
stDocName = "rptSemiMonthly"
DoCmd.OpenReport stDocName, acNormal
Exit Sub
End If
End If
Case Is = 3
stDocName = "rptStmtSummary"
DoCmd.OpenReport stDocName, acNormal
Case Is = 4 ' Billing Summary
stDocName = "rptBillingSummary"
DoCmd.OpenReport stDocName, acNormal
End Select
Exit_cmdPrintReport_Click:
Exit Sub
Err_cmdPrintReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintReport_Click
End Sub
I can use this code to print one of four reports. I am trying to adapt the code to be able to print statements for all the customers with one click. This project started as access 97 and has worked its way up
This code is functional if not elegant as I am a novice programmer. I used the recordset method to do some looping elsewhere in the project and was succesful.
As stated earlier, without the looping, the code evaluates the number of outstanding invoices for the first client as we are at .BOF but when I enable the loop it does loop through each client but appears to return 0 for intNumberRecords.
Unfortunately all the data is quite confidential for my business/clients
Thanks for your quick response