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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass a null string back from a function?

Status
Not open for further replies.

jgoodman00

Programmer
Jan 23, 2001
1,510
I have the following code:
Function IDWork(strref) As String
Dim db As Database, rst As Recordset, rstAdopt As Recordset
Set db = currentdb
Set rst = db.OpenRecordset("SELECT Pnamstr.* FROM Pnamstr WHERE (((Pnamstr.RefNo) = '" & strref & "'));")
Set rstAdopt = db.OpenRecordset("SELECT ADOPT.* FROM ADOPT WHERE (((ADOPT.RefNo) = '" & strref & "'));")
If rstAdopt!priority <> &quot;A&quot; Then
IDWork = rstAdopt!RefNo & rstAdopt!brsno
Else
IDWork = Null
End If
End Function

The idea is that if the priority is A, the string IDWork will be null. This is passed back to the calling function. For some reason it is producing an error on the line 'IDWork = Null'. At this point, the error message is 'Invalid use of null'


This seems a little strange. It works if I change it into a zero length string, but I would rather pass out null.

Any suggestions??? James Goodman
j.goodman00@btinternet.com
 
Instead of passing back a NULL, what about just assigning an empty string?

If rstAdopt!priority <> &quot;A&quot; Then
IDWork = rstAdopt!RefNo & rstAdopt!brsno
Else
IDWork = &quot;&quot;
End If
Terry M. Hoey
 
I didn't really want to pass back a zero length string. Kinda messy when it comes to update queries on that field, because some will have values, others none, & some zero length strings...

Is it actually possible to pass a null string out of a function, or am I trying to do something which is impossible?? James Goodman
j.goodman00@btinternet.com
 
James,

Strings cannot be null as far as I am aware. Seems to me you're attempting the impossible.

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top