Checking database fields for no data
My program reads Access DB table. I use the following code to make sure I only read the field if the data is there:
Code:
If (rs.Fields("COMMNT1") <> vbNull) Then
strCOMMNT1 = Trim(rs.Fields("COMMNT1"))
End if
However if the field is empty I get an error on the vbNull line. I'm thinking checking against the vbNull is not the right way to do it. How do I check for an empty field?
Re: Checking database fields for no data
The easier way to do this and not get the invalid use of null message would be:
vb Code:
strCOMMNT1 = Trim(rs.Fields("COMMNT1) & vbNullString)
This appends a null string ( empty string value '') to the database fields then performs the trim.
Re: Checking database fields for no data
You could also do
Code:
If Not IsNull(rs.Fields("COMMNT1")) Then
strCOMMNT1 = Trim(rs.Fields("COMMNT1"))
End if