Note that there are some explanatory texts on larger screens.

plurals
  1. POVB using a ADO Recordset inside a vb function, checking for null
    primarykey
    data
    text
    <p>I have some weird behavior that has me perplexed. I created a function in vb (Microsoft Word Macro version of VB) which looks like this:</p> <pre><code>Public Function isitnullorempty(newstring As String) As Boolean If IsNull(newstring) Or IsEmpty(newstring) Or newstring = "" Then isitnullorempty = False Else isitnullorempty = True End If End Function </code></pre> <p>It seems to work as expected if I create a variable and then set it to null, "", or leaving it empty. I manipulate the variable and then do MSGBOX isitnullorempty(variable) and it echos what I expect. It doesn't behave the same way when I put a recordset inside the function however. I've even tried to make a variable set it to the record set and then test it but that doesn't work either. If I try to invoke the following</p> <pre><code>'ADO query code here (This is an ODBC connection) DO While (Not oRecordset.EOF) MsgBox isitnullorempty(oRecordset.Fields("CustomerTypeRefFullName")) oRecordset.MoveNext Loop </code></pre> <p>This yields the error: Invalid use of Null. </p> <p>So two fold question. </p> <p>Is there already a vb function that exists which does what I want? Why does my code behave this way?</p> <p>Weirder yet is that if I do the test individually outside of the function, it works. </p> <p><strong>Temporary Solution</strong></p> <p>It writes more code than it needs to but since I can't seem to call the function with the recordset value I will just individually check each record according to my needs like this:</p> <pre><code> If IsNull(oRecordset.Fields("CustomerTypeRefFullName").Value) Or IsEmpty(oRecordset.Fields("CustomerTypeRefFullName").Value) Or oRecordset.Fields("CustomerTypeRefFullName").Value = "" Then MsgBox "potato" End If </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload