Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 6, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Null Handling in Database I/O

Nulls are still a problem in VB3/VB4-they cause unexpected errors. To handle them, you can read the MDB field into a variant, which can hold a null and then test for it later, or replace all nulls with blank strings to protect the application. To me, nulls serve no logical purpose. I prefer to eradicate them immediately. I have developed a family of I/O pick-up routines that I use at the physical interface next to the database field:
Public MyDB As Database
Public MyRS As Recordset
Dim TestVariant As Variant
Set MyDB = OpenDatabase("testjet3db")
Set MyRS = MyDB.OpenRecordset("NameTable")
'Sample Calls
TestVariant = ScreenForNull(MyRS![FirstName])
TestVariant = ScreenForNull(MyRS![FirstName], " ")
Public Function ScreenForNull(aField As Variant, Optional _
	ByVal DefaultReturn As Variant) As Variant
	If IsNull(aField) Then
		If Not _
			IsMissing(DefaultReturn) Then
			ScreenForNull = DefaultReturn
			ScreenForNull = ""
		End If
		ScreenForNull = aField
	End If
End Function
Stan Mlynek
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date