|
-
May 30th, 2000, 09:04 PM
#1
Thread Starter
Addicted Member
Hi. I'm stepping through a record set from a database, such as in the following code:
Code:
oRS.MoveFirst
Do while NOT oRS.eof
Dim fx as string
fx = oRS("FaxNumber")
oRS.MoveNext
Loop
oRS.Close
But in my database some of the faxnumber fields are empty. This is causing the following error:
"Runtime error 94: Invalid use of null"
I tried putting an if statement like
Code:
if oRS("FaxNumber") is NOT NULL then..
but that didn't work, for the same reasons...
I don't know enough about VB to know how to handle this... seems this worked fine when I did it in ASP...
tx
d8
-
May 30th, 2000, 09:51 PM
#2
Hyperactive Member
string variables don't like being set to null, same for text boxes. it can be a pain. the easiest way i've found for getting round it is: -
if isnull(oRS("FaxNumber")) = false then
fx = oRS("FaxNumber")
oRS.MoveNext
Loop
oRS.Close
i don't know why 'is not null' and '<> null' don't work. maybe someone out there who knows could explain it....
-
May 30th, 2000, 09:51 PM
#3
New Member
Hey dvst
This is a normal problem that everyone struggles thorugh when doing database work for the first time. Here is a quick peice of code that I wrote that illeviates that problem:
Code:
Function strClean(pvarString As Variant) As String
If IsNull(pvarString) Or IsEmpty(pvarString) Then
strClean = ""
Exit Function
End If
strClean = Trim(CStr(pvarString))
End Function
Use it like this:
Code:
oRS.MoveFirst
Do While NOT oRS.EOF
Dim fx as string
fx = strClean(oRS!FaxNumber)
oRS.MoveNext
Loop
oRS.Close
Hope this helps!
-
May 30th, 2000, 10:16 PM
#4
Thread Starter
Addicted Member
thanks!
thanks jimbob, and skippy!
skippy: nice work with that code! I'm implementing it!!
tx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|