Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime Error 94 3

Status
Not open for further replies.

28642864

Technical User
Mar 27, 2008
6
US
THIS is my code. I get the Invalid use of Null when the field is blank.

Private Sub Sitelink_Click()
Call fHandleFile(Me.Sitelink, WIN_NORMAL)

End Sub
------------------------
Someone suggested the below text to handle this. I'm not a programmer just user. What is NZ? Thanks


Simplicity, I wouldn't use Isnull in this situation...

if nz(<myfield>,"") = "" OR nz(<myfield2>,"") then
<myresult>
end if

The above example handles NULL and zero length string values and accomplishes the task efficiently.

M'kay? :)

Gary
gwinn7e
A+,N+,I+
 
nz = nonzero.

So the nz-function returns an empty string in case a nonzero value is encountered.

Pampers [afro]
Keeping it simple can be complicated
 
>> returns an empty string in case a nonzero value is encountered

Well, no. It returns whatever you put in as the second argument if the first argument is Null. So..

Nz([MyField],0) - will return the number 0 if MyField is Null.

Nz([MyField],"Gorilla") - will return "Gorilla" if MyField is Null.

But if [MyField] was an empty string "", then Nz would return an empty string in either of the two cases above.



 
Just for the fun of it...

What you say might be more precise, but refering to:
nz(<myfield>,"")
will indeed result in a ""

Also: If you use the Nz function in an expression or in a query without using the valueifnull argument (the second argument), the results will be a zero-length string in the fields that contain null values. ;)



Pampers [afro]
Keeping it simple can be complicated
 
This gives a runtime 13 now


Private Sub Sitelink_Click()
On Error GoTo Err_sitelink_click

Call fHandleFile(Me.Sitelink, WIN_NORMAL)

Err_sitelink_click:

If Nz(Sitelink, "") Then
Sitelink = ""
End If
End Sub
 
How about:

Call fHandleFile(Nz(Me.Sitelink,""), WIN_NORMAL)

Of course, I would need to see the code for fHandleFile to know if passing it an empty string would cause an error.

Pampers - maybe I should have said "Well, not necessarily".

 
How are ya 28642864 . . .

Realize . . . the [blue]Nz[/blue] function returns what you assign to the 2nd argument . . . not true/false! This makes you [blue]If[/blue] statement ambiguous, as it will never be true or false.

What you need to do is qualify [blue]Sitelink[/blue] before you call the subroutine:
Code:
[blue]Private Sub Sitelink_Click()
   [purple][b]Me.Sitelink = Nz(Me.Sitelink, "")[/b][/purple]
   
   If Me.Sitelink = "" Then
      MsgBox "your message here!"
   Else
      Call fHandleFile(Me.Sitelink, WIN_NORMAL)
   End If
   
End Sub[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks, Didn't want a message to appear or message box, but this worked to avoid the error.
 
Hi JoeAtWork,
No, you were right, I was not being very punctual (and then tried to cover it up, haha).

Tnx TheAceman1 for finishing it up

Pampers [afro]
Keeping it simple can be complicated
 
28642864 . . .

Without a [blue]MsgBox[/blue]:
Code:
[blue]Private Sub Sitelink_Click()
   
   If Nz(Me.Sitelink, "") <> "" Then
      Call fHandleFile(Me.Sitelink, WIN_NORMAL)
   End If
   
End Sub[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top