Empty DB field causing grief!!
HEllo all,
Should be a straightforward thing;
I have queried a table with field1, 2 and 3.
All fields are not always populated.
So when I allocated variables to, for instance, field3.
I will: field3var = rsMyRS![field3]
Now this will work if the field has got something in it, fair enough. And it the field is empty it will throw an error of :
invalid use of null
again, fair enough.
So to avoid the null error I wanted to put an if loop around like this:
Code:
If rsMyRS![field3] Is Null Then
Do something else
End If
But that doesnt work, and I get an Object required 424 error.
I have tried :
Code:
If rsMyRS![field3] is Empty...
And also
Code:
rsMyRS![field3] = ""
No luck.
Any ideas?
THanks
Ramo
Re: Empty DB field causing grief!!
How about
Code:
field3var = rsMyRS![field3] & vbNullString
Re: Empty DB field causing grief!!
Thanks, but...
Althought that works, I dont think its particularly good coding...
Is there not a way of checking if a db field is empty before allocating a variable to it.
Ramo
Re: Empty DB field causing grief!!
Re: Empty DB field causing grief!!
you could try
vb Code:
if len(rsMyRS![field3])=0 then
I normaly use rsMyRS(2) instead of having to type out the field names all the time. I find it easier to use as i can create a query and then add the fields in to excel and return the index by numbering each column.
cheers
David
Re: Empty DB field causing grief!!
isNull is the cookie...
Thanks for your help (and advice with field references).
Ramo
Re: Empty DB field causing grief!!
I usually use If Not IsNull(whatever) Then