Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In valid use of Null error message when form load event is called 1

Status
Not open for further replies.

fchan

MIS
Jul 2, 2001
47
US
I have two tables that have a one-to-many relationship. Table 1 has staff ID info and table 2 has staff leave of absence info.

I have a search form that the user can search using staff id or staff name. The search form opens the LeaveInput form which contains the LeaveRecord subform.

When the subform loads, it calls a procedure that is suppose to calculate the number of days between two dates that are fields on the subform.

If the LeaveInput form opens to a staff without any data in the LeaveRecord subform, I receive an error message that says, "Run time error: 94 Invalid use of null".

My sub procedure looks like this:

Private Sub Form_Load()
If Me.LeaveBeginDate = Null Or Me.LeaveEndDate = Null Then
Exit Sub
End If

If Me.LeaveEndDate > Date Then
Me.CurrentDays.Value = CInt(CalculateDays(Me.LeaveBeginDate, Date))
Else
Me.CurrentDays.Value = CInt(CalculateDays(Me.LeaveBeginDate, Me.LeaveEndDate))
End If
End Sub

It appears that I'm getting the error message because the Me.LeaveBeginDate and Me.LeaveEndDate are null. But when that happens I want form load event to exit the sub procedure.

I would appreciate any suggestions.

Thanks.
 
Although I haven't checked all of your code, but your syntax is wrong for evaluating for Null. Try this:

Private Sub Form_Load()
If IsNull(Me.LeaveBeginDate) Or IsNull(Me.LeaveEndDate)Then Exit Sub

Hope that helps.


Bob

 
Thanks Bob,

Your suggestion was on the mark. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top