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 SkipVought 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' - invalid use of null 1

Status
Not open for further replies.

eelsar

Technical User
May 20, 2002
36
0
0
US
I have the following problem:

On my subforms I assign the first name + last name (from the master form) to a text box in the form_current event of the subform. It works for the current record, however for a new record I get "runtime error 94' - invalid use of null"
The database that I am reading and writing from is currently empty except for the few test records.

this is the code that I have.
Private Sub Form_Current()
If Form_MasterForm.txtLastName.Value <> Null And Form_MasterForm.txtFirstName.Value <> Null Then
myString1 = Form_MasterForm.txtLastName
myString2 = Form_MasterForm.txtFirstName
Me.txtNameFromMaster = myString1 & &quot;, &quot; & myString2
End If
End Sub

Could anyone please help me.
thank you
 
Hi!

You need to use IsNull:

If IsNull(Form_MasterForm.txtLastName.Value) = True

etc.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Try the following:

Code:
Private Sub Form_Current()
If Len (Form_MasterForm.txtLastName.Value & &quot;&quot;) > 0 And Len (Form_MasterForm.txtFirstName.Value & &quot;&quot;) > 0 Then
myString1 = Form_MasterForm.txtLastName
myString2 = Form_MasterForm.txtFirstName
Me.txtNameFromMaster = myString1 & &quot;, &quot; & myString2
End If
End Sub

This works because null appended with an empty string is an empty string, and the length of an empty string is 0 rather than null.

John
 

Im not sure that <> works with NULL values

Try -

If (Not IsNull(Form_MasterForm.txtLastName.Value)) And (Not IsNull(Form_MasterForm.txtFirstName.Value)) Then...

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

if nz(<myfield>,&quot;&quot;) = &quot;&quot; OR nz(<myfield2>,&quot;&quot;) 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+
 
I have a similar problem. However, I set Box and in certain cases, Box2 = to a string. Box and Box2 are the names of unbound text boxes. I can set other fields or control values to the value of box. However, even step through in Visual Basic, box2 becomes (and before some changes box did too) Null. Why is becoming NULL consequently causing the invalid use of NULL error.

Here is my code:

Dim strNewRecord, strNewRecord2 As String
Dim dbox

Select Case Frame6
Case 1
Box = &quot;EyeColor&quot;
Case 2
Box = &quot;HairColor&quot;
Case 3
Box = &quot;MaritalStatus&quot;
Box2 = &quot;MAbbrv&quot;
dbox = 3
Case 4
Box = &quot;Service&quot;
Box2 = &quot;Sabbrv&quot;
dbox = 3
' additional cases follow...
End Select

Select Case dbox
Case 3
strNewRecord2 = &quot;SELECT info.&quot; & Box & &quot;, info.&quot; & Box2 & &quot; FROM Info WHERE Info.&quot; & Box & &quot; Is Not Null AND Info.&quot; & Box2 & &quot; Is Not Null&quot;

' **** Here, I begin setting controls equal to the value of Box -- including a calculated string that is set to the form's recordsource.

Label4.Caption = Box & &quot;: &quot;
CtrlSrc.ControlSource = Box
Label4a.Caption = Box2 & &quot;: &quot;
CtrlSrc2.ControlSource = Box2

Me.RecordSource = strNewRecord2

Case Else
strNewRecord = &quot;SELECT info.&quot; & Box & &quot; FROM Info WHERE Info.&quot; & Box & &quot; Is Not Null&quot;
Label4.Caption = Box & &quot;: &quot;
CtrlSrc.ControlSource = Box
Me.RecordSource = strNewRecord
CtrlSrc2.ControlSource = &quot;='No data' &quot;

End Select

Frame6 = 0
Box = &quot;&quot;
Box2 = &quot;&quot;
End Sub

Your help is appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top