Solved

Automatic resizing of forms and text boxes

Posted on 2006-07-02
18
1,055 Views
Last Modified: 2012-08-14
When data is inputted into a text box, I would like the box to grow vertically so that the entire text can be seen, and for the display to remain expanded.  At the same time, I would like the continuous form itself to grow vertically in response to the expanded text boxes.  This will give the most efficient and compact data display for my database.  Any suggestions on how this could be done, with code examples?  With thanks.
0
Comment
Question by:diddion
  • 5
  • 5
  • 3
  • +3
18 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17026304
So I take it u dont want a predefined large size? Would that not be easier for u. You can create scrollbars on that textbox.
There is the Can Grow/Shrink properties which resizes when printing, though not 100% sure if it applies to forms

0
 

Author Comment

by:diddion
ID: 17026336
Thanks - this is not what we are looking for.  This is a screen-based diary/record system, working as follows:

A task is created that is to be carried out for a client - this is the 'item' below..  Normally, that task is fairly short, but it may on occasions be quite long.  The task form includes a coninuous subform where notes are added - each note will be of different length.  When the task form is opened, what is needed is a view of all text shown in the task form and the subform - for example:

Date               Item                                   Notes

anydate           Check product submission     first note
                                                                subsequent long note with a lot of text
                                                                third brief note
                                                                 final note associated with the product submission

Clearly, one way rouind this would be to have large forms and large text boxes, but as many different tasks as possible need to be displayed on a single screen - so each new record must start off as a single line with the ability to grow vertically.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 17026407
This won't be possible as the CanGrow property applies onlyto reports and on a continuous form the detail section will match the largest field so when you change it in one row the other rows will increase just as much...

The only workaround I use in cases like this is an additional large textbox on the mainform and there the text of the current row's textbox is made visible in a large size.

Idea ?

Nic;o)
0
 

Author Comment

by:diddion
ID: 17026419
Thanks.   It doesn't matter if the other fields also grow.  What we're looking for is for the text box fields to grow vertically  according to the data input, with the record growing accordingly......
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17026471
ok, how does this sound. Its only a start. I havent figured out if one has entered text thats starts to scroll i..e too big for textbox

If height of texbox was 255 for example

And if user enters {ctrl enter} to add to a new line in that textbox, then resize at that point

Private Sub txtNote_KeyPress(KeyAscii As Integer)
    If KeyAscii = 10  Then   'ctrl enter hit
        txtNote.Height = txtNote.Height + 255
        MsgBox "Resized"
        Me.Repaint
    End If
End Sub


but then what u have to do is, if controls exist under this textbox, u have to reposition them (just the TOP property, simply add 255 to all of them)


0
 
LVL 54

Expert Comment

by:nico5038
ID: 17026505
Then setting the max height shouldn't be a problem too.
When it still doesn't fit for the newest entries, then a vertical scrollbar will be made available.

Nic;o)
0
 

Author Comment

by:diddion
ID: 17026528
Nic - thanks for this.  It works as you have indicated, but has the disadvantage that the text box is resized for all records - we only want it to be resized (and to stay that way) for the specific record.

Aslo, do you know how the form itself could be resized automaticallyto accommodate the enlarged field - again, specific to the record in question?
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 17026584
See this link:

http://support.microsoft.com/?kbid=213768#top

If this is more along the lines of what you want, maybe this macro would work on your form if you could use a data sheet view.
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

Author Comment

by:diddion
ID: 17026610
Don't think so in this case - we need to be more dynamic in the form resizing
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 17026716
Another idea.....Look into Smart tags if you have Access 2003+....the excerpt is from Microsoft's writeup:

Access 2003 uses smart tags for the following purposes:
·New! Error checking is made easier with smart tags. Access 2003 flags common errors on forms and reports and offers options for correcting them.
 
New! Propagating field properties is as simple as modifying a property in one location and then selecting to propagate the change throughout all controls bound to that field.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17026732
Because u use a continuous forms, u cant have individual fields based on the same control

You know there is always the zoombox
If u hit SHIFT F2 on a textbox, it brings up the zoombox

Perhaps u can go directly to the zoombox when they enter that field

0
 
LVL 54

Accepted Solution

by:
nico5038 earned 250 total points
ID: 17026775
With a continuous form you're just out of luck, you can't change the detail sections individually.
Thus my proposal to use a main/subform combination that will allow you to show the text in a separate large textbox on the main form.
The other option is to have an additional toggle button to allow the user to enlarge/shrink the textbox by code like that provided by rockiroads.

Nic;o)
0
 

Author Comment

by:diddion
ID: 17026808
Thanks for the help - please continue thinking!  I'm away on holiday and will pick this up on return.
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 250 total points
ID: 17026823
If u wanted the zoom, on the GotFocus of a textbox, u can add this code

DoCmd.RunCommand acCmdZoomBox

And it will bring up a zoombox


Enjoy your hols
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17031012
may not quite be what u want but you never know :)
http://www.experts-exchange.com/Databases/MS_Access/Q_21863559.html

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 17069823
Also,

(Not looking for any points)

Again, might not help much (this is only for automatically sizing Combo Boxes only)
But it might give you some ideas:
(Again, on a contionuous Form all of the comboBoxes will be the salme size)

(I think I got this from: vbaccelerator.com)
 
This tip shows you how to get and set the width of the drop down portion of a combo box. It also includes code to automatically set the drop down width based on the contents of a combo box by measuring the size of the text in each combo box item.

Start a new project and add a module. Then add the following code to the module:
' These functions required to set the drop-down width:
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const CB_GETDROPPEDWIDTH = &H15F
Private Const CB_SETDROPPEDWIDTH = &H160

' These are only required if you want to automatically
' calculate the drop-down width:
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Const DT_CALCRECT = &H400

Public Property Let DropDownWidth(ByRef cboThis As ComboBox, ByVal lWidth As Long)
    SendMessageLong cboThis.hwnd, CB_SETDROPPEDWIDTH, lWidth, 0
End Property
Public Property Get DropDownWidth(ByRef cboThis As ComboBox) As Long
Dim lW As Long
    DropDownWidth = SendMessageLong(cboThis.hwnd, CB_GETDROPPEDWIDTH, 0, 0)
End Property
Public Sub DropDownWidthFromContents(ByRef cboThis As ComboBox, Optional ByVal lMaxWidth = -1)
Dim i As Long
Dim tR As RECT
Dim lW As Long
Dim lWidth As Long
Dim lHDC As Long

    ' Evaluate the width of each item in the
    ' combo box:
   
    ' First set the combo's parent form font to the
    ' combo font:
    With cboThis.Parent.Font
        .Name = cboThis.Font.Name
        .Size = cboThis.Font.Size
        .Bold = cboThis.Font.Bold
        ' Surely you don't have a combo box with
        ' italic font?
        .Italic = cboThis.Font.Italic
    End With
    ' Cache the HDC of the parent form for speed:
    lHDC = cboThis.Parent.hdc
   
    ' Loop through each combo box list item & get its
    ' width, storing the largest:
    For i = 0 To cboThis.ListCount - 1
        DrawText lHDC, cboThis.List(i), -1, tR, DT_CALCRECT
        lW = tR.Right - tR.Left + 8
        If (lW > lWidth) Then
            lWidth = lW
        End If
    Next i
   
    ' Don't allow width to exceed specified max
    ' width, or the width of the screen:
    If lMaxWidth <= 0 Then
        lMaxWidth = Screen.Width \ Screen.TwipsPerPixelX - 16
    End If
    If (lWidth > lMaxWidth) Then
        lWidth = lMaxWidth
    End If
   
    ' Combo box looks a bit strange when the
    ' drop down portion is smaller than the
    ' combo box itself:
    If (lWidth < cboThis.Width \ Screen.TwipsPerPixelX) Then
        lWidth = cboThis.Width \ Screen.TwipsPerPixelX
    End If
   
    ' Set the drop down width:
    DropDownWidth(cboThis) = lWidth
End Sub
To try out a the function, add a Combo box, a Label and three Command buttons to your project's form. Set the captions for the command buttons as follows:     Command1     A&dd String
    Command2     &Calc Width
    Command3     &Set Width...
Then add this code to the form:
Private Sub Command1_Click()
Dim sI As String
    sI = InputBox("Enter string", , "New item")
    If (sI <> "") Then
        Combo1.AddItem sI
    End If
End Sub

Private Sub Command2_Click()
    DropDownWidthFromContents Combo1
    Label1.Caption = DropDownWidth(Combo1)
End Sub

Private Sub Command3_Click()
Dim sI As String
    sI = InputBox("Enter width", , DropDownWidth(Combo1))
    If IsNumeric(sI) Then
        DropDownWidth(Combo1) = CLng(sI)
        Label1.Caption = DropDownWidth(Combo1)
    End If
End Sub

Private Sub Form_Load()
    Label1.Caption = DropDownWidth(Combo1)
End Sub
Start the project. The width of the combo box wil lbe added to the label control. You can use the Add String button to add new items to the combo box, Calc Width to automatically set the drop down width to the control's contents and Set Width to set your own width. Note that all widths are specified in pixels.
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 17256277
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Split: nico5038 {http:#17026775} & rockiroads {http:#17026823}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

jjafferr
EE Cleanup Volunteer
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now