I think the "On No Data event" is the way to go, but there are alternatives.
I prefer to use saved queries for form/report record sources because it is easier to check for errors and correct record selections.
You could create two saved queries for the reports: "qrySampleOrderConf" and "qryOrderConfPS1".
Then change your code to something like:
Code:
Private Sub RetailerID_Click()
Dim bHasRecs As Boolean
'set default value
bHasRecs = False
If [IsSample] = True Then
bHasRecs = fcnRptHasRecs("qrySampleOrderConf")
If bHasRecs Then
DoCmd.OpenForm "F-OrderConf", acNormal, , "[ConfNum] =" & [Forms]![F-OrderList]![ConfNum], acFormEdit, acWindowNormal
' DoCmd.Close acReport, "rptSampleOrderConf", acSavePrompt '<<<---this line is not needed now
Else
DoCmd.OpenReport "rptSampleOrderConf", acViewNormal, , "[ConfNum] =" & [Forms]![F-OrderList]![ConfNum], acWindowNormal
End If
Else
bHasRecs = fcnRptHasRecs("qryOrderConfPS1")
If bHasRecs Then
DoCmd.OpenForm "F-OrderConf", acNormal, , "[ConfNum] =" & [Forms]![F-OrderList]![ConfNum], acFormEdit, acWindowNormal
' DoCmd.Close acReport, "rptOrderConfPS1", acSavePrompt '<<<---this line is not needed now
Else
DoCmd.OpenReport "rptOrderConfPS1", acViewNormal, , "[ConfNum] =" & [Forms]![F-OrderList]![ConfNum], acFormEdit, acWindowNormal
End If
End If
DoCmd.Close acForm, "F-OrderList" ', acSavePrompt '<<<---parameter not needed
End Sub
'------------------------------------------------------
Function fcnRptHasRecs(qQuery As String) As Boolean
Dim r As DAO.Recordset
fcnRptHasRecs = False
Set r = CurrentDb.OpenRecordset(qQuery)
If Not r.BOF And Not r.EOF Then
r.MoveLast
r.MoveFirst
fcnRptHasRecs = (r.RecordCount > 0)
End If
r.Close
'clean up
Set r = Nothing
End Function
Since the query is opened to check for records and the opening the report depends on there being records, it kind of works like the "On No Data event".
BTW, you had (have) two lines in your code that don't do what you might think they do.
Code:
DoCmd.Close acReport, "rptOrderConfPS1", acSavePrompt
DoCmd.Close acForm, "F-OrderList", acSavePrompt
The syntax of this command is
expression.Close(ObjectType, ObjectName, Save)
The "Save" parameter does not save the data entered, it is for changes to the DESIGN of the form/report.
From Help:
Save Parameter (Optional) = A AcCloseSave constant that specifies whether or not to save changes to the object. The default value is acSavePrompt.
Using VBA, you can open a form/report in design view (hidden or visible) and change the design of the object; change size, BG color, add controls, move controls, etc. When you close the object, you would have the option to save or discard the changes to the object.
My $0.02........