You will be doing yourself a favor if you use meaningful names for your
command buttons, combo boxes, etc.
Assuming Combo61 is an unbound combo box from which the user selects a
report from a list, you could put the code into the After Update event for
Combo61. Maybe something like this:
Private Sub Combo61_AfterUpdate()
Dim strRptName As Variant
strRptName = Me!Combo61
DoCmd.OpenReport strRptName, acViewPreview
End Sub
Did you compile the code (Debug >> Compile)? If so, did it work? I ask
because AFAIK acViewReport is not a valid option. What exactly are you
trying to do with that option?
You should add the following to the top of all code modules, just below
Option Compare Database:
Option Explicit
In the VBA editor, click Tools >> Options. Click the Editor tab, and check
the box for Require Variable Declaration. It could be that Access is
allowing acViewReport as a variable, not caring that it is not defined as
anything. strRptName is a valid string variable (you are assigning a value
to a declared string variable (the Dim statement declares the variable).
However, without Option Explicit an undeclared variable will be assumed to
be a variable of variant type, even though it means nothing in context.
Back to the original question, if there is a reason using the command button
is the best option, you can use the Click event to test whether Combo61 is
null:
Private Sub Command50_Click()
Dim varRptName As Variant
varRptName = Me!Combo61
If IsNull varRptName Then
MsgBox "Please select a report."
Me.Combo61.SetFocus
Else
DoCmd.OpenReport varRptName, acViewPreview
End If
End Sub
Note that the variable is a variant, which can be null. A string cannot,
which would have been handled, but it would have complicated the code.
Also, I used acViewPreview, which lets you look at the report rather than
having it print immediately.