If statements blanks form when no results on query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am attempting to code so that when a form opens it grabs a query result and
if there is a value then it will show a MsgBox.

It works fine when there is a result (checking if User Login Name is the
result). However, if there are no results on the query it blanks the form.

My If statement included in the Click Event is:

If [qry_UnCompleteCU].[EnteredBy] = strUser Then

MsgBox "You have Uncompleted Requests - Please review and update."

End If

Is there a workaround if there are no results in the query?

Thanks.
 
What do you want it to do if there query result is blank? If you know what
you want to do, then code for a null result:

If IsNull([Query.Result]) Then
Msgbox "There is no data to return", vbokonly, "Information"
Exit Sub
Else
Your code...

B
 
If there is no result, I want it to just exit the routine and not show a
message.

Is IsNull the proper funciton when there are no results?
 
I changed code to:

If IsNull([qry_UnCompleteCU].[EnteredBy) Then

Exit Sub

Else

MsgBox "You have Uncompleted Requests - Please review and update."

End If

And now get the error: "The expression you are entered refers to an olbject
that is closed or doesn't exist."
 
Gary,

You a missing a closed ] after EnteredBy

Your code: If IsNull([qry_UnCompleteCU].[EnteredBy) Then

Should be: If IsNull([qry_UnCompleteCU].[EnteredBy]) Then

That should work. If not, you can also try:

If [qry_UnCompleteCU].[EnteredBy] = " " Then

or try

If [qry_UnCompleteCU].[EnteredBy] = " " or IsNull([qry_UnCompleteCU].
[EnteredBy] Then

B
 
Back
Top