tags:

views:

176

answers:

2

USING MS ACCESS 2003

How to check is null value in the access database?

My code.

Public Function DateToString(dte As Date) As String
Dim d As String
Dim m As String
Dim y As String
d = Day(dte)
m = Month(dte)
y = Year(dte)
If Len(d) = 1 Then d = "0" & d
If Len(m) = 1 Then m = "0" & m
DateToString = y & m & d
End Function


Public Function StringToDate(txt As String) As Date
Dim dte As String
dte = Left(txt, 4) & "-" & Mid(txt, 5, 2) & "-" & Right(txt, 2)
StringToDate = CDate(dte)
End Function




sql1 = "CREATE TABLE MOI (PreDate varchar(50))"
sql2 = "INSERT INTO MOI values('" & StringToDate(rsCardEvent1.Fields("PreDate"))  "')"

From the above function, I want to check if not null then my code else no need.

Need VB 6.0 Code Help?

A: 

If the item is actually coming is as a string, then do:

if not txt is vbNullString then
    ' code here
end if
Michael Todd
Showing error in "txt"
Gopal
It might not be coming in as a string. You might try Mitch Wheat's method; it seems a bit more robust.
Michael Todd
+1  A: 

To check for Null in a dataset field:

If IsNull(rs("colname")) Then 
  'Field contains a Null Value 
Else 
  'Field does 'not' contain a Null Value 
End If

To check for null or Empty string:

If (txt & "") = "" Then 
  ' txt is Null or empty
End If
Mitch Wheat
While Running Showing error "Invalid use of null"
Gopal
@ Gopal: please show us your code; it's no good just saying it doesn't work! The methods I have posted are tried and tested.
Mitch Wheat
@Mitch Wheat. I posted my code, Go through, i used your code, in my code, but it showing "Invalid Use of NUll"
Gopal