2 potential approaches
Code:
Private Sub cmdFlagged_Click()
Dim fRec As Integer
fRec = DCount("[ID]", "qryFlagged")
'if no records flagged then do not open frmFlagged and show msgbox
If fRec = 0 Then
MsgBox "You Have NO Records Flagged.", vbInformation
Else
MsgBox "You Have " & fRec & " Records Flagged for Review!", vbInformation
DoCmd.OpenForm "frmFlagged", acNormal
End If
End Sub
or how to exit on one condition and default to another
Code:
Private Sub cmdFlagged_Click()
Dim fRec As Integer
fRec = DCount("[ID]", "qryFlagged")
'if no records flagged then do not open frmFlagged and show msgbox
If fRec = 0 Then
MsgBox "You Have NO Records Flagged.", vbInformation
Exit Sub
End If
MsgBox "You Have " & fRec & " Records Flagged for Review!", vbInformation
DoCmd.OpenForm "frmFlagged", acNormal
End Sub
They have the same line count I'd say. Either are a bit less cryptic and don't rely on what seem to be happy accidents in your code.