-
I'm trying to create a sample connection to the Nwind.mdb through code. All connections are fine until I encounter a record that has a blank field. I get an error as soon as I encounter this. Am I supposed to be coding for invalid use of null ? If so, could someone give an example ? TIA
-
text1.text = rs!Name & ""
if the rs!Name (or any other variable) is null then adding "" to it will make it a blank string instead.
or use IsNull(rs!Name) to check if it is null before trying to assign it to a textbox etc
-
iif function
you also can use the iif function like...
text1.text = iif(IsNull(.Field(0)),"",.Field(0))
-
IIF's should be used sparingly, if at all. They are slow, they always evaluate both conditions and if one side fails (even if it's not the side passing evaluation), the whole statement fails.
-
Another simple way is using the trim function:
Code:
Text1.Text = Trim("" & rs!Name)
Good Look!
-
you don't even have to use the trim:
Text1.Text = "" & rs!Name