keep getting error

lipin

Registered User.
Local time
Today, 14:29
Joined
May 21, 2002
Messages
149
I have a combobox and 3 textboxes. THe 3 textboxes are populated depending on the number in the combobox. I keep getting the INVALID USE OF NULL error when the combo box receives the focus and then the user tabs to the next box without entering a number. But I want the user to be able to do this. Here is my code:

Private Sub Employee_Exit(Cancel As Integer)
If IsNull(Employee) Then Exit Sub

Dim strName As String
Dim strShift As String
Dim strDept As String

strName = [Employee].Column(1) <---error is here when I
txtname = strName debug

strShift = [Employee].Column(2)
txtshift2 = strShift

strDept = [Employee].Column(3)
txtjob = strDept
End Sub

I thought the If isnull at the beginning would eliminate error but it doesn't. How can I avoid NULL error?
 
Try using the After Update event instead of the Exit Event. This way it only changes the text boxes when the Combo Box has actually been altered.

Also, Here is a good replacement for IsNull, It works for more than just strings, it also checks Type Number, Boolean, Currency, etc...

Sample Call:

If IsNothing(Me.ComboBox) Then Exit Sub

Function IsNothing(varToTest As Variant) As Integer
' Tests for a "logical" nothing based on data type
' Empty and Null = Nothing
' Number = 0 is Nothing
' Zero length string is Nothing
' Date/Time is never Nothing

IsNothing = True

Select Case VarType(varToTest)
Case vbEmpty
Exit Function
Case vbNull
Exit Function
Case vbBoolean
If varToTest Then IsNothing = False
Case vbByte, vbInteger, vbLong, vbSingle, vbDouble, vbCurrency
If varToTest <> 0 Then IsNothing = False
Case vbDate
IsNothing = False
Case vbString
If (Len(varToTest) <> 0 And varToTest <> " ") Then IsNothing = False
End Select

End Function
 

Users who are viewing this thread

Back
Top Bottom