isnull not working any ideas?

R

Rivers

If IsNull(Forcasted.Form![time avg]) = False Then
h = Forcasted.Form![time avg]
[Forcasted Time to Tip] = h * d
[Forcast amended] = -1
Else

End If
theres my code but its not working the 'h' variable keeps calling up a an
error because its null but the isnull is supposed to catch this can anyone
advise me where the codes is going wrong please

hanks in advance
 
K

Ken Snell \(MVP\)

The "time avg" control may be able to hold an empty string value? Try this:

If Len(Forcasted.Form![time avg] & "") > 0 Then
h = Forcasted.Form![time avg]
[Forcasted Time to Tip] = h * d
[Forcast amended] = -1
Else

End If

What is "Forcasted"? Is that the name of a subform control on a main form?
 
R

Rivers

What is "Forcasted"? Is that the name of a subform control on a main form?
yes it is a subform on a form and when it does not have a linked record is
empty therefore i tried the isnull again the len is showing the same error


Ken Snell (MVP) said:
The "time avg" control may be able to hold an empty string value? Try this:

If Len(Forcasted.Form![time avg] & "") > 0 Then
h = Forcasted.Form![time avg]
[Forcasted Time to Tip] = h * d
[Forcast amended] = -1
Else

End If

What is "Forcasted"? Is that the name of a subform control on a main form?

--

Ken Snell
<MS ACCESS MVP>



Rivers said:
If IsNull(Forcasted.Form![time avg]) = False Then
h = Forcasted.Form![time avg]
[Forcasted Time to Tip] = h * d
[Forcast amended] = -1
Else

End If
theres my code but its not working the 'h' variable keeps calling up a an
error because its null but the isnull is supposed to catch this can anyone
advise me where the codes is going wrong please

hanks in advance
 
P

Pat Keller

Try the nz function?

If Len(nz(Forcasted.Form![time avg])) > 0



Rivers said:
What is "Forcasted"? Is that the name of a subform control on a main form?
yes it is a subform on a form and when it does not have a linked record is
empty therefore i tried the isnull again the len is showing the same error


Ken Snell (MVP) said:
The "time avg" control may be able to hold an empty string value? Try this:

If Len(Forcasted.Form![time avg] & "") > 0 Then
h = Forcasted.Form![time avg]
[Forcasted Time to Tip] = h * d
[Forcast amended] = -1
Else

End If

What is "Forcasted"? Is that the name of a subform control on a main form?

--

Ken Snell
<MS ACCESS MVP>



Rivers said:
If IsNull(Forcasted.Form![time avg]) = False Then
h = Forcasted.Form![time avg]
[Forcasted Time to Tip] = h * d
[Forcast amended] = -1
Else

End If
theres my code but its not working the 'h' variable keeps calling up a an
error because its null but the isnull is supposed to catch this can anyone
advise me where the codes is going wrong please

hanks in advance
 
K

Ken Snell \(MVP\)

When the subform is empty, ACCESS does not instantiate the controls on that
subform. Therefore, the control that you're trying to reference does not
exist when you run your code, and therefore you get an error in the
operation of the IsNull or Len function.

So, let's change the approach to test if the subform has any records before
you do the IsNull or Len test:

If Forcasted.Form.RecordsetClone.RecordCount <> 0 Then
If Len(Forcasted.Form![time avg] & "") > 0 Then
h = Forcasted.Form![time avg]
[Forcasted Time to Tip] = h * d
[Forcast amended] = -1
End If
End If

--

Ken Snell
<MS ACCESS MVP>





Rivers said:
What is "Forcasted"? Is that the name of a subform control on a main form?
yes it is a subform on a form and when it does not have a linked record is
empty therefore i tried the isnull again the len is showing the same
error


Ken Snell (MVP) said:
The "time avg" control may be able to hold an empty string value? Try
this:

If Len(Forcasted.Form![time avg] & "") > 0 Then
h = Forcasted.Form![time avg]
[Forcasted Time to Tip] = h * d
[Forcast amended] = -1
Else

End If

What is "Forcasted"? Is that the name of a subform control on a main
form?

--

Ken Snell
<MS ACCESS MVP>



Rivers said:
If IsNull(Forcasted.Form![time avg]) = False Then
h = Forcasted.Form![time avg]
[Forcasted Time to Tip] = h * d
[Forcast amended] = -1
Else

End If
theres my code but its not working the 'h' variable keeps calling up a
an
error because its null but the isnull is supposed to catch this can
anyone
advise me where the codes is going wrong please

hanks in advance
 

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