well, your initial post left off any mention of the option group and the
reports. when posting in the ngs, it pays to keep in mind that nobody here
can see your database or anything in it; we're entirely dependent on the
information that you include in your post.
now that you've described, hopefully, the complete picture, i can say with
some confidence that you can use the code i posted, replacing the line
<put here the code to "run the query">
with the complete Select Case statement that you posted. here's the combined
code, as
If IsNull(Me!Date1) Or IsNull(Me!Date2) Or IsNull(Me!cboOne) _
Or IsNull(Me!cboTwo) Then
Msgbox "Enter a value in each field, please."
Else
Select Case Me!fraPrint
Case 1
DoCmd.OpenReport "R-By_Date", acViewPreview
DoCmd.Maximize
Case 2
DoCmd.OpenReport "R-By_Eval", acViewPreview
DoCmd.Maximize
Case 3
DoCmd.OpenReport "R-By_W/C", acViewPreview
DoCmd.Maximize
' If you don't chose a default value, this generates
' a message box if the user clicks a button without
' making a selection
Case Else
MsgBox "Select Report", vbExclamation, "Reports"
End Select
End If
hth
George said:
Tina - On my form as mentioned I have two date fields and two Combo boxes and
an option group to select which report opens based on a single query. After
you fill in the four fields and select the report you click on a search
button that has this code in the "On Click" Event. How can I stop it from
running if one of the fields are blank ?
Private Sub Command13_Click()
On Error GoTo ErrorPreview
Select Case [fraPrint]
Case Is = 1
DoCmd.OpenReport "R-By_Date", acViewPreview
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "R-By_Eval", acViewPreview
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "R-By_W/C", acViewPreview
DoCmd.Maximize
' If you don't chose a default value, this generates a message box if the
user clicks a button without making a selection
Case Else
MsgBox "Select Report", vbExclamation, "Reports"
End Select
ExitPreview:
Exit Sub
ErrorPreview:
MsgBox Err.Description
Resume ExitPreview
End Sub
Thanks - George
tina said:
On my form I have two Date Fields and Two Combo Boxes. Once all the data
is
entered in the fields you click on a search button that runs the query.
according to your original post, above, you had code on a button "that runs
the query". i just gave you the code to check the search controls, and told
you where to insert the code you said you already have.
since the code you've now posted is using Select Case to open various
reports based on the value of what i assume is an option group control, i'm
not quite sure what you're doing. how about explaining how we jumped from
running a query to opening reports, and just where/when it is that you want
to check for null values in the controls you cited in your first post.
hth
Thanks - I can not figure out the last part, <put here the code to "run
the
query">
This is what I started with and then I added what you said to the bottom
of
my code which I am sure is wrong. I get an error message for the Else
statement.
When I click on my form's Command Button it first looks at an option group
then runs the query.
Private Sub Command13_Click()
On Error GoTo ErrorPreview
Select Case [fraPrint]
Case Is = 1
DoCmd.OpenReport "R-By_Date", acViewPreview
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "R-By_Eval", acViewPreview
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "R-By_W/C", acViewPreview
DoCmd.Maximize
' If you don't chose a default value, this generates a message box if the
user clicks a button without making a selection
Case Else
MsgBox "Select Report", vbExclamation, "Reports"
End Select
ExitPreview:
Exit Sub
ErrorPreview:
MsgBox Err.Description
Resume ExitPreview
Private Sub Command13_Click()
If IsNull(Me!cboStartDate) Or IsNull(Me!cboStopDate) Or
IsNull(Me!Combo
- Eval) Or IsNull(Me!Combo - Rating) Then
MsgBox "Data Required In Each Field."
Else
Command13_Click()
End If
End Sub
:
try adding the following to the command button's procedure, as
If IsNull(Me!Date1) Or IsNull(Me!Date2) Or IsNull(Me!cboOne) _
Or IsNull(Me!cboTwo) Then
Msgbox "Enter a value in each field, please."
Else
<put here the code to "run the query">
End If
replace Date1, Date2, cboOne, and cboTwo with the correct names of the
controls, of course.
hth
On my form I have two Date Fields and Two Combo Boxes. Once all the
data
is
entered in the fields you click on a search button that runs the
query.
All
that works as intended. What I want to add is a function that will
stop it
from running if one of the fields are blank. None of the fields are
connected
to a table so I can't use the "Required" function. I tried "Not Null"
in
the
Validation Rule - but that doesn't work either.
Any ideas ?
Thanks - George