If statements blanks form when no results on query

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.
 
B

bhipwell via AccessMonster.com

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
 
G

Guest

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?
 
G

Guest

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."
 
B

bhipwell via AccessMonster.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top