Approach User Support homepage Approach User Support
Answers to Frequently Asked Questions about Lotus Approach
Examples LotusScripts
Example databases
Links to other Lotus Approach support services

[Return to contents]

Example LotusScript: Using keydown event to automatically enter or modify a date

Last updated: before December, 1998

Written by Jerry Sikes <Unisource Converting>, 1997
(C) Copyright 1997 by Jerry Sikes
Permission is granted to freely copy this script in electronic form,
or to print for personal use. It may be used in any Approach database,
but may not be distributed for profit either by itself or as part of
a collection or database.
Disclaimer: This script is provided as is without any express or
implied warranties. The author assumes no responsibility for errors or
omissions, or for damages resulting from the use of the information contained
herein, or your own version containing your desires for the usage of the
script.

The scheduled manufacturing date of an order in our plant is always set to a
Monday's date. (Scheduled week of) All orders for that week are numerically
sequenced. The main table for this app is a Lotus Notes view whose selection
formula returns only unscheduled orders. The scheduler uses two Approach
applications in a tiled top - bottom view. The second app is the same Notes
database but based on a Notes view with a selection formula that returns only
scheduled orders. The objective of the script is to allow the scheduler to
press the + key to return this Mondays date and additional + keystrokes
increments the date by 7 days. This script allows normal date typing. It does
not intefer with the use of the spacebar to set the current month-day-year.
It does not intefer with normal tabbing through the field. Dates in scripting
are variants, My source as fieldbox is FoldStartDate, a date field. But when
scripting reads a fieldbox, it reads the text representation of the date,
thus Datevalue() must be used to convert the text to variant type.
DateNumber(Year,Month,Day) is used to modify the date. Year, month and day
are integer values and can be additive. DateNumber(97+1,12-1,14+6)=11/20/98.

Sub Keydown(Source As Fieldbox, Charcode As Long, Repeats As Integer, Flags As Integer, Overridedefault As Integer)
        Dim td As Variant,wd As Integer,ay As Integer, am As Integer, ad As Integer
        If charcode=107 Then
                currentview.body.fold_id.SetFocus
'I have to temporarily move out of the source field to check/change its contents
                If source.text="" Then
'True condition when FoldStartDate is blank
                        td = Date$   'Current system date
                        wd%=Weekday(td)
                        ay%=Year(td)
                        am%=Month(td)
                        ad%=Day(td)
                        source.text=Datenumber(ay% ,am%, (ad%-(wd%-2)))
                        source.setfocus
                Else
'False condition when FoldStartDate is not blank
                        td = Datevalue(source.text)
                        wd%=Weekday(td)
                        ay%=Year(td)
                        am%=Month(td)
                        ad%=Day(td)
                        source.text=Datenumber(ay% ,am%, (ad%+7))
                        source.setfocus
                End If
        End If
End Sub
'---------------------------------------------------------------------------
This is the next field in the tab order is called ReadyDate, which indicates
the ready date at plant after all production operations. It's keydown script
is similiar to the above script but initially uses the FoldStartDate(if not
blank) with a + keystroke and then increments by one day each additional +
keystroke.
Sub Keydown(Source As Fieldbox, Charcode As Long, Repeats As Integer, Flags As Integer, Overridedefault As Integer)
        Dim td As Variant,wd As Integer,ay As Integer, am As Integer, ad As Integer
        If charcode=107 Then
                currentview.body.fold_id.SetFocus
                If source.text="" Then
                        If currentview.body.FoldStartDate.text="" Then
                                td = Date$
                                wd%=Weekday(td)
                                ay%=Year(td)
                                am%=Month(td)
                                ad%=Day(td)
                                source.text=Datenumber(ay% ,am%, ad%)
                                source.setfocus
                        Else
                                td = Datevalue(currentview.body.FoldStartDate.text)
                                wd%=Weekday(td)
                                ay%=Year(td)
                                am%=Month(td)
                                ad%=Day(td)
                                source.text=Datenumber(ay% ,am%, ad%)
                                source.setfocus
                        End If
                Else
                        td = Datevalue(source.text)
                        wd%=Weekday(td)
                        ay%=Year(td)
                        am%=Month(td)
                        ad%=Day(td)
                        source.text=Datenumber(ay% ,am%, (ad%+1))
                        source.setfocus
                End If
        End If
End Sub

[Return to contents]

© Copyright, JohnBrown, Trademarks, Disclaimer, Acknowledgements.