Zero length String?

B

Bongard

Hi, I have a TEXT field in my query whose criteria is a Function
NodeFilter(). This function looks to a form that allows the user to
fill in data and then runs the query. When the user enters criteriea
the Function works just fine and the query is run successfully.
However when the user leaves this field ([NodeF]) on the form blank I
cannot get the query to run successfully without any criteria in the
Node field. I continue to get 0 results on my query if the criteria is
left blank

Here is my function being passed as the query's criteria:

Function NodeFilter()

If IsNull([Forms]![frm_EditMaxMVCF]![Nodef]) Then
GoTo EndSub
Else: NodeFilter = [Forms]![frm_EditMaxMVCF]![Nodef]
End If

Exit Function

EndSub:
NodeFilter = isnull([Forms]![frm_EditMaxMVCF]![NodeF])

End Function


When the field is left blank it does come out as isnull() and in VB as
I step through the function it runs down to the "EndSub:" but the
query doesn't like and of the criteria I feed it. Besides "NodeFilter
= isnull([Forms]![frm_EditMaxMVCF]![NodeF])" I have also tried the
following:

NodeFilter = ""
NodeFilter = 0

Any help or suggestions would be much appreciated!

-Brian
 
B

BruceM

I see a few things. I don't think you can have End Sub within a function,
and GoTo is best avoided except for error handling, but there is no need
anyhow. Just test for Not IsNull:
If Not IsNull([Forms]![frm_EditMaxMVCF]![Nodef]) Then
NodeFilter = [Forms]![frm_EditMaxMVCF]![Nodef]
End If

Or maybe you could use the Nz function without testing for Null:
NodeFilter = Nz([Forms]![frm_EditMaxMVCF]![Nodef])

See Help for more about Nz.

Also, Else doesn't have a colon after it, and I think the Else condition
needs to be on the next line, if you need to go that route:
Else
NodeFilter = [Forms]![frm_EditMaxMVCF]![Nodef]

But what is the point of the function? If you are trying to pass the value
of [Forms]![frm_EditMaxMVCF]![Nodef] to the text box, you can just set the
text box Control Source to:
=Nz([Forms]![frm_EditMaxMVCF]![Nodef])
In code, you could use the form's Current event, or another event if if
works better:
Me.YourTextBox = Nz([Forms]![frm_EditMaxMVCF]![Nodef])

Or you could use the function, with the syntax corrected, if you need to use
one of several different events to get the value.

If you need to set NodeFilter to an empty string, doing so at the start of
the function may be the best choice, but I don't think it is necessary.
 

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