Selasa, 20 Maret 2012

Re: [MS_AccessPros] Invalid Use of Null error

 

John,
 
Nevermind I forgot to take out the NOT in the IF Not Me.NewRecord. New Code:
 
Private Sub Form_Current()
 
If Me.NewRecord Or IsNull(Me.EndTime) Or IsNull(Me.StartTime) Then
  Me.txtElaspedTime = ""
Else
  Me.txtElaspedTime = GetElapsedTime([EndTime] - [StartTime])
 
End If
End Sub
Private Sub Form_Load()
If Not Me.NewRecord Then
    Me.Caption = Nz("Unit Number: " & Me.[UnitID], "No Unit Listed")
   
End If
If Me.NewRecord Or IsNull(Me.EndTime) Or IsNull(Me.StartTime) Then
  Me.txtElaspedTime = ""
Else
  Me.txtElaspedTime = GetElapsedTime([EndTime] - [StartTime])
 
End If
End Sub
 
Thank you very much

With warm regards,

Arthur Lorenzini
Sioux Falls, South Dakota

________________________________
From: John Viescas <JohnV@msn.com>
To: MS_Access_Professionals@yahoogroups.com
Sent: Tuesday, March 20, 2012 10:12 AM
Subject: RE: [MS_AccessPros] Invalid Use of Null error


 

Art-

If either EndTime or StartTime is Null, that is what is causing the error. Try
this:

Private Sub Form_Load()

If Me.NewRecord Or IsNull(Me.EndTime) Or IsNull(Me.StartTime) Then
Me.txtElaspedTime = ""
Else
Me.txtElaspedTime = GetElapsedTime([EndTime] - [StartTime])
End If

End Sub

Private Sub Form_Current()

If Me.NewRecord Or IsNull(Me.EndTime) Or IsNull(Me.StartTime) Then
Me.txtElaspedTime = ""
Else
Me.txtElaspedTime = GetElapsedTime([EndTime] - [StartTime])
End If
End Sub

John Viescas, author
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Microsoft Access Applications
Microsoft Office Access 2003 Inside Out
SQL Queries for Mere Mortals
http://www.viescas.com/
(Paris, France)

---------------------------------

From: MS_Access_Professionals@yahoogroups.com
[mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of Art
Sent: Tuesday, March 20, 2012 3:59 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Invalid Use of Null error

 
I found this function for calculating elaspe time but when I move to a new
record I recieve a "Invalid Use of Null". I think I understanding th cause but I
am not sure how to fix it. Please advise.

Here is the code:

Function GetElapsedTime(interval)

Dim totalhours As Long, totalminutes As Long, totalseconds As _
Long
Dim days As Long, hours As Long, Minutes As Long, Seconds As Long

days = Int(CSng(interval))
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
totalseconds = Int(CSng(interval * 86400))
hours = totalhours Mod 24
Minutes = totalminutes Mod 60
Seconds = totalseconds Mod 60

GetElapsedTime = days & " Days " & hours & " Hours " & Minutes & _
" Minutes " & Seconds & " Seconds "

End Function

Private Sub Form_Load()

If Not Me.NewRecord Then
Me.txtElaspedTime = GetElapsedTime([EndTime] - [StartTime])
Else
Me.txtElaspedTime = ""

End If

End Sub

Private Sub Form_Current()

If Not Me.NewRecord Then
Me.txtElaspedTime = GetElapsedTime([EndTime] - [StartTime])
Else
Me.txtElaspedTime = ""

End If
End Sub

Thank you,

Arthur Lorenzini
Siooux Falls, SD

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar