Not recognizing is null in if statement

G

Gary S

Not sure why this is not working, it will not
recognize the is null when it should:

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
Dim Text1 As Variant
Dim Text2 As Variant
Dim Text3 As Variant
Dim Text4 As Variant
Dim Text5 As Variant

Text1 = Me.CustomerPOCName
Text2 = Me.CustomerCompany
Text3 = Me.CustAdd1
Text4 = Me.CustAdd2
Text5 = Me.CustFullAdd

'1st movement pass
If Text1 Is Null Then
Text1 = Text2
Text2 = Null
End If

If Text2 Is Null Then
Text2 = Text3
Text3 = Null
End If

If Text3 Is Null Then
Text3 = Text4
Text4 = Null
End If

If Text4 Is Null Then
Text4 = Text5
Text5 = Null
End If



Me.txtAdd1 = Text1
Me.txtAdd2 = Text2
Me.txtAdd3 = Text3
Me.txtAdd4 = Text4
Me.txtAdd5 = Text5

End Sub
 
D

dymondjack

"Is Null" is for SQL statements

The IsNull() function does the same for VBA.

The Nz() function is a commonly used one as well. It returns a value of
your choice if the value is null...

If Nz(Text4, "") = "" Then
Text4 = Text5
End If

The above tells VBA 'if text4 is null, pretend its "" for this expression.'
This is very useful for checking for null AND zero-length strings at the same
time.

--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top