Roger's Access Library Homepage
Forum Home Forum Home > Other Download Libraries > MS Access MVP Libraries > Tejpal, A.D.
  New Posts New Posts RSS Feed - Form_ControlDefaultValues
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

>
Want a good read? Try The Summer of His Life (available on Amazon!)

Form_ControlDefaultValues

 Post Reply Post Reply
Author
Message
A.D. Tejpal View Drop Down
Microsoft MVP
Microsoft MVP


Joined: 30 Jun 2008
Status: Offline
Points: 192
Post Options Post Options   Thanks (0) Thanks(0)   Quote A.D. Tejpal Quote  Post ReplyReply Direct Link To This Post Topic: Form_ControlDefaultValues
    Posted: 21 Mar 2011 at 11:57pm

Form_ControlDefaultValues
Explanatory Notes

    This sample db demonstrates programmatic setting of default values for form controls, covering different data types (Date, Text and Number). Two methods are illustrated as follows:
   
1 - Concatenation of intended default value into a string assigned as control's default value property.
    2 - Generation of intended default value through embedded reference within the string assigned as control's default value property.

    For each of the above styles, two alternative modes are demonstrated as follows:
    (a) Set defaults as per current record (On editing or double clicking pertinent controls).
    (b) Set defaults as per last record (On editing or double clicking pertinent controls - only if the cursor is on last record).

    Double click on first column (ID) clears default values for all controls.

    At each stage, the latest record whose values have been used for setting up the defaults, gets highlighted in distinct color. Simultaneously, the new record is highlighted in similar color so as to provide visual correlation. If the current record happens to be other than these two records, it gets highlighted in a separate color.

    For implementing style 1, intended default values are processed through a user defined function so as to take care of appropriate enclosing delimiters for date and text data types, apart from fixing embedded quotes (if any) in text type values. In addition, date type values are properly formatted before concatenation so as to ensure consistent results, despite differing regional settings for short date format. This approach is preferred over the oft adopted simple expedient of merely enclosing the intended default values within outer quotes, irrespective of the data type (as in such a case, it leads to a default value that is not a true live date or number, though the aberration gets masked in case of bound controls).

    Style 2 mentioned above, represents an entirely new approach. It provides appropriate data type in case of dates or numbers, at the same time eliminating the need for worrying about delimiters for date or text type data. Moreover, there is no need for fixing embedded quotes in text type data or for pre-formatting of dates to take care of local regional settings for short date format. This is achieved through an embedded reference within the string assigned as default value. In this context, form level public collection of control values is utilized.

    Note: It would have been much simpler to use embedded reference to the control for setting its default value. However, it is observed that such a technique works only if the reference happens to be to a control other than the one whose default value is being set. For example:  MyControl.DefaultValue = "[SomeOtherControl]"

Version: Access 2000 file format.

References:  Nothing Extra.

Download >>:  uploads/37/Form_ControlDefaultValues.zip
--

Email: adtejpal@gmail.com
Back to Top
Sponsored Links
>
Want a good read? Try The Summer of His Life (available on Amazon!)

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.03
Copyright ©2001-2019 Web Wiz Ltd.