Selasa, 20 Maret 2012

[MS_AccessPros] Re: Invalid Use of Null error

 

John,
I curious why you use:
Me.txtElaspedTime = ""
rather than:
Me.txtElaspedTime = Null

Apparently txtElaspedTime is unbound.

You could also get rid of the On Current code and use a Control Source like:
=GetElapsedTime(Nz(EndTime-StartTime,0))

I think it is good to write functions that trap for nulls and other possible issues.

Duane Hookom
MS Access MVP

--- In MS_Access_Professionals@yahoogroups.com, John Viescas <JohnV@...> wrote:
>
> 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
>

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar