[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1477
  • Last Modified:

Run-Time Error 94 - Invalid Use of Null

I created a text box (txtText) and pasted this function in the Control Source:
=GetTestType(Nz([cboTestType]). This text field is used only for display purposes.

When user selects an item from cboTestType, the item selected is displayed both in the combo and the textbox (txtTest).

Problem:
How do I correct this Run-Time error 94?
When user selects an item from a cboTestType, user gets: Run-Time error 94 - "Invalid use of Null"

.......on...
GetTestType = DLookup("TestType", "tblTest", "TestlID='" & myPID & "'")

...from the function below:

Public Function GetTestType(myPID As String) As String
If Len(myPID) < 2 Then
GetTestType = "" ' or whatever you want to dislpay in this case
Else
GetTestType = DLookup("TestType", "tblTest", "TestlID='" & myPID & "'")  '<<== Error line
End If
End Function
0
billcute
Asked:
billcute
  • 2
  • 2
1 Solution
 
tbsgadiCommented:
Hi billcute,

GetTestType = nz(DLookup("TestType", "tblTest", "TestlID='" & myPID & "'"))

Good Luck!

Gary
0
 
billcuteAuthor Commented:
tbsgadi:
Could you please provide an explanation why "nz" was placed before "DLookup"?
The same function worked for me in other texttype boxes.

Regards
Bill
0
 
billcuteAuthor Commented:
tbsgadi:
Is there any way I can let you know of my future posts?
Regards
Bill
0
 
tbsgadiCommented:
The nz turns nulls into "".
You probably didn't have nulls before.
If I'm online I'll see your posts
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now