[AccessD] Using DateDiff function CORRECTED QUESTION

Henry Simpson hsimpson88 at hotmail.com
Tue Feb 11 18:44:00 CST 2003


I'd lose the Exit Sub.  If the code ever gets error handling and object 
termination and cleanup (if objects are added), your object clean up may 
never run.  In your example, the Exit Sub is entirely redundant anyway.  It 
is good coding practice to have every procedure exit in one place only so 
any cleanup is guaranteed to run.  Your example provide two alternate exit 
points (End Sub and Exit Sub) depending on the variables.  This revision is 
no faster or slower, but it's less typing and code storage.  For really long 
and convoluted deeply nested IF's and loops, an Exit Sub statement makes for 
easy code interpretation but in this example, I'd say it is redundant.

I usually write:  "If Msgbox "  ",, = vbYes rather than the other way 
around.  I like your way of having the answer condition up front as the 
logic is more immediately evident.


Hen



>From: Bob Gajewski <bob at renaissancesiding.com>
>Reply-To: accessd at databaseadvisors.com
>To: "'accessd at databaseadvisors.com'" <accessd at databaseadvisors.com>
>Subject: RE: [AccessD] Using DateDiff function CORRECTED QUESTION
>Date: Tue, 11 Feb 2003 15:56:36 -0500
>
>Charles
>
>I realize that. The answer proposed by Arthur and my alternate both use
>MsgBox, as the situation requires user decision. I was questioning whether
>there was an appreciable difference between using MsgBox then checking for
>vbNo versus "If vbNo = MsgBox ..." .
>
>Thanks,
>Bob Gajewski
>
>On Tuesday, February 11, 2003 15:39 PM, Wortz, Charles
>[SMTP:CWortz at tea.state.tx.us] wrote:
> > Bob,
> >
> > Whenever you have a MsgBox() you have to wait for the user response,
> > which is measured in seconds.  Think of the thousands of lines of your
> > code that could be running while you await the user response
> >
> > Charles Wortz
> > Software Development Division
> > Texas Education Agency
> > 1701 N. Congress Ave
> > Austin, TX 78701-1494
> > 512-463-9493
> > CWortz at tea.state.tx.us
> > (SELECT * FROM users WHERE clue > 0)
> >
> >
> > -----Original Message-----
> > From: Bob Gajewski [mailto:bob at renaissancesiding.com]
> > Sent: Tuesday 2003 Feb 11 14:26
> > To: 'accessd at databaseadvisors.com'
> > Subject: RE: [AccessD] Using DateDiff function CORRECTED QUESTION
> >
> > CORRECTION
> >
> > Arthur
> >
> > (Almost) totally unrelated question, but I imagine you know the answer
> > Which is more efficient?
> >
> > **************************************************************
> > Private Sub Command20_Click()
> > If DateDiff("h", Now, LastRun()) <= 15 Then
> >    If vbNo = MsgBox("You've already updated the records today." & vbCrLf
> > & _
> >       "Are you sure that you want to update them again?", vbYesNo +
> > vbQuestion, "Alert")
> >       Exit Sub
> >    Else
> >       DoCmd.RunMacro "GetRates"
> >    End If
> > End If
> > End Sub
> > **************************************************************
> >
> > or your response to Oleg?
> >
> > I'm desperately trying to streamline my code for processing speed, and I
> > would appreciate any thoughts you have on this
> >
> > TIA,
> > Bob Gajewski
> >
> >
> > On Tuesday, February 11, 2003 15:00 PM, Arthur Fuller
> > [SMTP:artful at rogers.com] wrote:
> > > Yet another opportunity for me to praise static functions :-) Put this
> >
> > > into a public module:
> > >
> > > Static Function LastRun() as Date
> > > Dim dtNow as Date
> > > If IsNull(dtNow) Then
> > > 	dtNow = Now()
> > > End If
> > > LastRun = dtNow
> > > End Function
> > >
> > > Now call this function from your click:
> > >
> > > Private Sub Command20_Click()
> > > Dim Andy
> > > If DateDiff("h", Now, LastRun()) <= 15 Then
> > > Andy = MsgBox("You've already updated the records today" & vbCrLf & _
> > >         "Are you sure you wish to update again?", vbYesNo, "alert")
> > >   If Andy = vbNo Then
> > >     Exit Sub
> > >   End If
> > > End If
> > > DoCmd.RunMacro "GetRates"
> > > End Sub
> > >
> > > Or, perhaps better, in the OnCurrent event of the form, set the
> > > availability of the button and forget the "You bungling user" message
> > > :-)
> > >
> > > Command20.Enabled = DateDiff("h", Now, LastRun()) > 15
> > >
> > > Which of course poses problems if the user is likely to have the form
> > > open on the same record for hours and hours, but if that is a
> > > possibility you can put the line above into its own function and call
> > > that function from a timer Hth,
> > > Arthur
> > >
> > _______________________________________________
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> > .
>
>_______________________________________________
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail




More information about the AccessD mailing list