Access97: Functions cannot return Null???

  • Thread starter Thread starter Jonathan Scott via AccessMonster.com
  • Start date Start date
J

Jonathan Scott via AccessMonster.com

I am writing a function that returns a TableDef, and when there is no
TableDef to return, I try to return Null. Problem is I get a "Object
required" error when I try to assign Null to the function name.(actual
error message is in Japanese, sorry if the error message is not exactly the
same in English)

Fine. I will just catch the error, and return without assigning anything.
But wait, IsNull() is not correctly detecting what should have been a Null
return value!

The compiler likes my assigning a Null for return. Why doesn't the runtime?

Public Function getTable(thisDB As TableDefs, thisTableName As String) As
tableDef
On Error GoTo getTable_ERROR
Set getTable = thisDB(thisTableName)
Exit Function

getTable_ERROR:
Set getTable = Null
End Function

Jonathan Scott
 
I am not sure but try setting the function to Nothing and then check this
with IsObject rather than Null and IsNull().

HTH
Van T. Dinh
MVP (Access)
 
Jonathan said:
I am writing a function that returns a TableDef, and when there is no
TableDef to return, I try to return Null. Problem is I get a "Object
required" error when I try to assign Null to the function name.(actual
error message is in Japanese, sorry if the error message is not
exactly the same in English)

Fine. I will just catch the error, and return without assigning
anything. But wait, IsNull() is not correctly detecting what should
have been a Null return value!

The compiler likes my assigning a Null for return. Why doesn't the
runtime?

Public Function getTable(thisDB As TableDefs, thisTableName As
String) As tableDef
On Error GoTo getTable_ERROR
Set getTable = thisDB(thisTableName)
Exit Function

getTable_ERROR:
Set getTable = Null
End Function

Jonathan Scott

I'm pretty sure that only a function with a return type of variant can
return Null.
 
I finally got it to work, but I am curious now what the difference could be
between Null and Nothing?

Jonathan Scott
 
So Nothing works?

An Object variable (including function returning an Object can be a
"Nothing" but not Null AFAIK since Null is an unassigned *value*.
 
BTW, note the subtle difference in A2000:

'----
public function fn()

end function
'----


?vartype(fn())
0
?isEmpty(fn())
True
?isNull(fn())
False

A97:
? isempty(eval("fn()"))
True
A2000:
isNull(eval("fn()"))
True

In A2000, when a function returns Empty, Eval converts that to Null

(david)
 
Back
Top