X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Automatically Enlarge Form Controls When Entered    
post Sep 19 2013, 05:14 PM

Posts: 9,239
Joined: 21-June 07

Just a very simple couple of functions.
Automatically enlarge a small textbox when user enters it. Automatically reduce it to its original size when user exits it.
Often times small forms must be designed to meet the needs of users with a variety of screen resolutions. This is a handy way to fit small textboxes on a small form, while still having them enlarged when the user enters it.
Great for memo or comment-type fields.
  1. In your database's VBA project, insert a standard module. at the top of the module (after any Option statements), type this code:
    Global lngControlHeight As Long
    Global lngControlWidth As Long
  2. In the code behind your Access form, at very top of the form-level module (right after any Option statements), paste these two functions:
    Function EnlargeControl()
    Dim ctl As Control
    Set ctl = ActiveControl
    lngControlHeight = ctl.Height
    lngControlWidth = ctl.Width
    ctl.Width = lngControlWidth * 2
    ctl.Height = lngControlHeight * 5
    End Function

    Function ShrinkControl()
    Dim ctl As Control
    Set ctl = ActiveControl
    ctl.Height = lngControlHeight
    ctl.Width = lngControlWidth
    End Function
  3. Adjust widths/heights as desired.
  4. Select any controls that you wish to have this feature (recommendation: Memo, comment, text type of fields where substantial amount of typing is anticipated). In the control's Property sheet, on Events tab, put this for the Enter event: =EnlargeControl() then hit Enter. Still on the properties window, type this in the Exit event: =ShrinkControl() and hit Enter.

Consider using TempVars instead of a global variable. I don't always recommend TempVars and I believe they have their drawbacks - however, in the case of this function, you'd hate for a global variable to lose its value by virtue of some other unhandled error in your application, leaving you stuck with an enlarged control. Due to this they are worth considering for this function if you are on Access 2007 or later.
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    18th December 2018 - 07:58 AM