Returning invalid use of Null error

G

Guest

Hi All,

I have an issue with an If statement.
The scenario:
for a current client, the user double clicks a client namein a listbox - the
client file opens. Fields on the form are visible according to client type.
Create an new client, open form called clienttype select type from option
frame, on click open client form in dataentry mode with fields hidden or
visible according to client type.

The problem:

On execution of the code, the open new client scenario works, however
opening an existing client has an error 94 message "invalid use of null". I
tried to get around it with a GoTo statement but it hasn't helped. The error
is occuring immediately after the End If statement. What should I have in my
syntax if the form is to load without the clienttype form being open?

Private Sub Form_Load()
If CurrentProject.AllForms(ClientType).IsLoaded Then
If Forms!ClientType.Frame1 = 2 Then Me.Check109.DefaultValue = True Else
Me.Check109.DefaultValue = False
Else: GoTo 100
End If
100
Me.Combo85.Visible = (Check109 = False)
Me.DOB.Visible = (Check109 = False)
Me.FirstName.Visible = (Check109 = False)
Me.MiddleNames.Visible = (Check109 = False)
Me.LastName.Visible = (Check109 = False)
Me.Text113.Visible = (Check109 = True)

End Sub
 
R

RoyVidar

bizpro wrote in message
Hi All,

I have an issue with an If statement.
The scenario:
for a current client, the user double clicks a client namein a listbox - the
client file opens. Fields on the form are visible according to client type.
Create an new client, open form called clienttype select type from option
frame, on click open client form in dataentry mode with fields hidden or
visible according to client type.

The problem:

On execution of the code, the open new client scenario works, however
opening an existing client has an error 94 message "invalid use of null". I
tried to get around it with a GoTo statement but it hasn't helped. The error
is occuring immediately after the End If statement. What should I have in my
syntax if the form is to load without the clienttype form being open?

Private Sub Form_Load()
If CurrentProject.AllForms(ClientType).IsLoaded Then
If Forms!ClientType.Frame1 = 2 Then Me.Check109.DefaultValue = True Else
Me.Check109.DefaultValue = False
Else: GoTo 100
End If
100
Me.Combo85.Visible = (Check109 = False)
Me.DOB.Visible = (Check109 = False)
Me.FirstName.Visible = (Check109 = False)
Me.MiddleNames.Visible = (Check109 = False)
Me.LastName.Visible = (Check109 = False)
Me.Text113.Visible = (Check109 = True)

End Sub


Could it be because you are assigning defaultvalue to the checkbox
and not value?

Also the code toggling the visible property of the controls will be
executed regardless of the criterions above, is that the intention?
 
G

Guest

Thanks for your response.

Assigning a value instead of a defaultvalue doesn't make any difference to
the later error.
And yes, the toggling needs to run based on the client type of the existing
client when the form opens.

Essentially the problem only occurs when an existing client is actioned due
to the fact that the form "clienttype" is not loaded. This form is only
loaded if a new client is created.
 
R

RoyVidar

bizpro wrote in message
Thanks for your response.

Assigning a value instead of a defaultvalue doesn't make any difference to
the later error.
And yes, the toggling needs to run based on the client type of the existing
client when the form opens.

Essentially the problem only occurs when an existing client is actioned due
to the fact that the form "clienttype" is not loaded. This form is only
loaded if a new client is created.


As far as I can see, your error occurs because the checbox is
Null when you try to use it's value to toggle the other controls
visible property.

Setting the defaultvalue, as you do if the other form is open,
seems to give the checkbox a value, but since you do not
assign neither defaultvalue nor value if the other form isn't
open, then the control will still be Null, causing the error in
the later assigning.

You will either need to assign a value to the control also
if the other form isn't open, or bind the checkbox to a field
in the forms recordsource or use something else to determine
what to assign the .visible property of the other controls.
 
G

Guest

Thanks Roy,

The checkbox is a bound control denoting client type and can not have a null
value based on the validation settings in the table. The weirdest thing
though, I removed the GoTo and just left the Else: and it now works
perfectly. Why it wouldn't do that for me earlier I don't know. Most
appreciative of your help.
 
G

Guest

The saga continues. I have found the error lies in the fact that the first If
statement is returning a false value instead of True.

Private Sub Form_Load()

If CurrentProject.AllForms(ClientType).IsLoaded Then ...

This code is returning False even when the form ClientType is loaded.
Presumably it cannot see the form because of some setting I have applied,
however, I can't see what it might be.
 

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