B
Burton
I probably am going about this wrong, but I think it will be the easiest way
if it is possible. I have a form with numerous combo boxes, list boxes, and
text boxes. It functions as a query for my table. Users can come in and
select parameters and it spits out a query and then that query is fed into a
report which is actually what shows up when you hit the "Execute Query"
button.
I am now trying to create Error messages based on a few different situations.
(1) If a user doesn't select anything on the form and then tries to press
"execute query", a message box will appear that says "Please select query
parameters".
(2) If a user selects "execute query" and the parameters they selected don't
return any results, I want the message box to say "No employees met these
parameters."
(3) If a user fails to place operators in between selections and then
selects "Execute Query" I want the message box to come up and say "Please
make sure all parameters are accompanied by appropriate operator (and/or)"
So I have gotten it so that the first message box works, but the second one
and third ones aren't entirely working. Sometimes the "No employees met these
parameters" pops up when the "Please make sure all parameters are accompanied
by appropriate operator (and/or)" should have popped up. I am really trying
to determine if there is a way to write a statement in VB that says "When MY
QUERY isn't created, then return the open message box "Please make sure all
parameters are accompanied by appropriate operator (and/or)". Otherwise, open
the message box saying "No employees met these parameters."
My logic is that if the query is created, it must have all of the operators
it needs, and so if the record count is 0 then is just meant that there were
no records that met the parameters. However, if the query isn't created at
all, it means that there was an operator problem and therefore the 3rd
message should apply.
Here is the code I am using right now that is occasionally causing message 2
to appear when message 3 should:
On Error Resume Next
Err.Clear
CurrentDb.CreateQueryDef "junk", "select * from staffing_matrix where "
& fields
If Err.Description = "" Then
If DCount("*", "junk") = 0 Then
MsgBox ("No Employees Meet These Parameters")
Else
Dim stDocName As String
stDocName = "Query Report"
DoCmd.OpenReport stDocName, acPreview
End If
Else
If Text74.Value = "" Then
MsgBox ("Please enter query paramaters")
Else
MsgBox ("Missing Operator(s) in Query Expression. Make sure that all
selected values" & vbNewLine & "have corresponding operators (and internal
operators where necessary)")
End If
End If
On Error GoTo 0
if it is possible. I have a form with numerous combo boxes, list boxes, and
text boxes. It functions as a query for my table. Users can come in and
select parameters and it spits out a query and then that query is fed into a
report which is actually what shows up when you hit the "Execute Query"
button.
I am now trying to create Error messages based on a few different situations.
(1) If a user doesn't select anything on the form and then tries to press
"execute query", a message box will appear that says "Please select query
parameters".
(2) If a user selects "execute query" and the parameters they selected don't
return any results, I want the message box to say "No employees met these
parameters."
(3) If a user fails to place operators in between selections and then
selects "Execute Query" I want the message box to come up and say "Please
make sure all parameters are accompanied by appropriate operator (and/or)"
So I have gotten it so that the first message box works, but the second one
and third ones aren't entirely working. Sometimes the "No employees met these
parameters" pops up when the "Please make sure all parameters are accompanied
by appropriate operator (and/or)" should have popped up. I am really trying
to determine if there is a way to write a statement in VB that says "When MY
QUERY isn't created, then return the open message box "Please make sure all
parameters are accompanied by appropriate operator (and/or)". Otherwise, open
the message box saying "No employees met these parameters."
My logic is that if the query is created, it must have all of the operators
it needs, and so if the record count is 0 then is just meant that there were
no records that met the parameters. However, if the query isn't created at
all, it means that there was an operator problem and therefore the 3rd
message should apply.
Here is the code I am using right now that is occasionally causing message 2
to appear when message 3 should:
On Error Resume Next
Err.Clear
CurrentDb.CreateQueryDef "junk", "select * from staffing_matrix where "
& fields
If Err.Description = "" Then
If DCount("*", "junk") = 0 Then
MsgBox ("No Employees Meet These Parameters")
Else
Dim stDocName As String
stDocName = "Query Report"
DoCmd.OpenReport stDocName, acPreview
End If
Else
If Text74.Value = "" Then
MsgBox ("Please enter query paramaters")
Else
MsgBox ("Missing Operator(s) in Query Expression. Make sure that all
selected values" & vbNewLine & "have corresponding operators (and internal
operators where necessary)")
End If
End If
On Error GoTo 0