Topic Options
#13368 - 08/22/06 12:58 PM Empty Database Field
Van Offline
OL Newbie

Registered: 06/26/06
Posts: 21
Loc: Texas
I need to pull information form a mdb database but when a field is empty I get the following error in my write statement:

W3602 : Error 0 on line 64, column 6: Microsoft VBScript runtime error: Type mismatch: 'Write'
W3603 : Error running script.
PWScript: W1603 : Plugin failed

When I put something in the database field it work fine.

Here is my database read statement:
obj_Database.Open "SELECT * FROM Sheet1 where Actno = " & ls_act & "", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+DATASOURCE+";Persist Security Info=False"
if not obj_Database.EOF then
ls_name = obj_Database.Fields("Name1")
ls_add1 = obj_Database.Fields("Name2")

And here is my write statement:
l_textOutput.Write(ls_name)
l_textOutput.WriteLine(ls_add1)


Thanks

Top
#13369 - 08/22/06 01:26 PM Re: Empty Database Field
Philippe F. Offline
OL Expert

Registered: 09/06/00
Posts: 1923
Loc: Objectif Lune, Montreal, Qc
Type mismatches are a fairly common problem when pulling data from a JET database (e.g. Access or Excel). The data type returned by the Fields() statement when the field is empty is probably a Null value, which can't be converted to a string and therefore generates an error. Other database drivers sometimes return an empty string instead ( "" ), which would not cause any problems.

In your case, try checking for the null value by using code like to this:
Code:
if not isNull(ls_name) then
   l_textOutput.Write(ls_name)
end if
That should do the trick.
_________________________
Technical Product Manager
I don't want to achieve immortality through my work; I want to achieve immortality through not dying - Woody Allen

Top
#13370 - 08/22/06 01:57 PM Re: Empty Database Field
Van Offline
OL Newbie

Registered: 06/26/06
Posts: 21
Loc: Texas
That works.

Thank you!

Top