If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Access97: Functions cannot return Null???
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 -- Message posted via http://www.accessmonster.com |
#2
|
|||
|
|||
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 Scott via AccessMonster.com" wrote in message news:e63d9bad3599422791df634c4075ec92@AccessMonste r.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 -- Message posted via http://www.accessmonster.com |
#3
|
|||
|
|||
Jonathan Scott via AccessMonster.com wrote:
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 don't check the Email account attached to this message. Send instead to... RBrandt at Hunter dot com |
#4
|
|||
|
|||
I finally got it to work, but I am curious now what the difference could be
between Null and Nothing? Jonathan Scott -- Message posted via http://www.accessmonster.com |
#5
|
|||
|
|||
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*. -- HTH Van T. Dinh MVP (Access) "Jonathan Scott via AccessMonster.com" wrote in message news:a850a4b6a15449f298ac879c18b4eba7@AccessMonste r.com... I finally got it to work, but I am curious now what the difference could be between Null and Nothing? Jonathan Scott -- Message posted via http://www.accessmonster.com |
#6
|
|||
|
|||
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) "Jonathan Scott via AccessMonster.com" wrote in message news:a850a4b6a15449f298ac879c18b4eba7@AccessMonste r.com... I finally got it to work, but I am curious now what the difference could be between Null and Nothing? Jonathan Scott -- Message posted via http://www.accessmonster.com |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UNION query question | Dale Peart | Running & Setting Up Queries | 6 | July 14th, 2004 12:26 AM |
Access inconsistencies | Hoopie | Running & Setting Up Queries | 2 | June 15th, 2004 10:53 AM |
Using IIF to return a zero value for a null | Muraii | Running & Setting Up Queries | 2 | May 29th, 2004 04:06 AM |