[AccessD] Using DateDiff function CORRECTED QUESTION

Arthur Fuller artful at rogers.com
Tue Feb 11 16:13:00 CST 2003


In that case, I'd still use a similar approach, and update the button text
to include the dateTime of LastRun(), so the user can see before clicking
when the last update was performed, and (large leap here :-) click only if
he means it.

You raise two good points.

1. If this update process is user-independent, then a static function won't
work.

2. If you want the value to persist longer than the lifetime of a program
run, you have no choice but to write LastUpdate() to a file for subsequent
retrieval. 

There are many ways to do this. One very simple one is to create a one-row
table containing a column for every such value; then you can easily retrieve
any value and all users will retrieve the same value.

Slightly more involved is JC's approach, in which each value is stored as a
row rather than a column. This allows users (and developers) to add new
persistent values at run-time. Depending on the number of values and the
frequency of their need during program execution, you could read them in as
required using Dlookup() -- which won't take long since there's only one row
returned, or read them all in at load-time so they are available at any
instant you need them. Without knowing a lot more about your app, it's
impossible to say which approach may suit you better.

Hth,
Arthur

-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com] On Behalf Of Oleg_123 at xuppa.com
Sent: February 11, 2003 4:41 PM
To: accessd at databaseadvisors.com
Subject: RE: [AccessD] Using DateDiff function CORRECTED QUESTION

well it's not telling them they've done something wrong, it's jst asking
whether they are sure they want to do it again (which may be the
possibility in this case)


> The version I like the best calls the static function from the OnCurrent
> event of the form, then sets the button's enabled property accordingly.
> A central goal of my interface designs is to make the user feel graceful
> not clumsy. To that end, anywhere I can eliminate the need to tell him
> that he's wrong, I do so. If the button is disabled, he can't click it,
> and will never see the message that tells he's done something wrong.
> Additionally, it eliminates one more click from the UI, which is a good
> thing.
>
> -----Original Message-----
> From: accessd-admin at databaseadvisors.com
> [mailto:accessd-admin at databaseadvisors.com] On Behalf Of Bob Gajewski
> Sent: February 11, 2003 3:26 PM
> 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
>>
>> -----Original Message-----
>> From: accessd-admin at databaseadvisors.com
>> [mailto:accessd-admin at databaseadvisors.com] On Behalf Of
> Oleg_123 at xuppa.com
>> Sent: February 11, 2003 1:53 PM
>> To: accessd at databaseadvisors.com
>> Subject: [AccessD] Using DateDiff function
>>
>> Hey, I am trying to make sure a user doesn'y click on  same button
>> twice in one day by mistake. I wrote this; doesn't work caz LastRun
>> keeps getting redefined if it starts over. Maybe I should an invisible
>> label to store latest update date and then check against the label ?
>>
>> -------------------------------------------------------
>> Dim LastRun
>>
>> Private Sub Command20_Click()
>> Dim Andy
>>
>> If DateDiff("h", Now, LastRun) <= 15 Then
>> Andy = MsgBox("You've alredy 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"
>>
>> LastRun = Now
>> End Sub
>>
>>
>> -----------------------------------------
>> Send a Xuppa Valentine to Your Sweetheart today!
>> http://www.xuppa.com/greet/
>>
>>
>> _______________________________________________
>> 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
>>
>
> _______________________________________________
> 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



-----------------------------------------
Send a Xuppa Valentine to Your Sweetheart today!
http://www.xuppa.com/greet/


_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list