Solved

Create auto-adjusting notes field

Posted on 2012-03-19
5
281 Views
Last Modified: 2012-03-20
I need the notes field in the attached database form to auto-adjust it's size based on the content entered on the form.  Is this possible?
Assigned-Tasks.accdb
0
Comment
Question by:rtod2
5 Comments
 
LVL 77

Assisted Solution

by:peter57r
peter57r earned 167 total points
ID: 37741347
You can use code like this to adjust the height based on my guesses about how much space the average character and line takes up.  You can adjust the settings of 90 characters per line and height per line in twips to get a better result.

The code goes into the form_current event procedure:

Dim x As Long
Dim Cpl As Integer, Lines As Integer, TwipsperLine As Integer
Cpl = 90   'chars per line
TwipsperLine = 280 ' allowing 280 twips per line
x = Len(Me.Note & " ")
Lines = x \ 90 + 1    ' minimum of 1 line
Me!txtNote.Height = TwipsperLine * Lines
0
 
LVL 39

Assisted Solution

by:als315
als315 earned 166 total points
ID: 37741489
If you are adding line breaks to your text (with CTRL+Enter) you should also count these breaks:
Public Function lines_qty(A As String) As Integer
Dim i As Long, j As Long
i = 0
For lines_qty = 0 To 1000
 j = InStr(i + 1, A, vbCrLf)
 If j > 0 Then
    i = j
 Else
    Exit Function
 End If
Next lines_qty
End Function

Open in new window

0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 167 total points
ID: 37742420
This is always a common question with no real "Solution".

The other Experts have posted ways to do this, but no technique is inherently "Perfect".

Differences in Fonts also make this even more complex.
(What works well for Times New Roman, may not work well for Arial)

Also note that you did not really specify if the control would "Auto-Adjust" based on the length of the string, or the size of the font, or if line breaks are taken into consideration, (or some combination of all three)...

For example:
This is 20 characters:
iiiiiiiiiiiiiiiiiiii
...But so is this:
WWWWWWWWWWWWWWWWWWWW
...so what size do you make a 20 character textbox?

Sure,,you could use a "0' as the "average character (as MS does), but again, this will sometimes make some controls too big, and others not big enough...

If this is for data entry, then are you looking for this to adjust the size of the control "As You Type"?

If this is for display purposes, you can set the Can Grow property to Yes, and the control will grow "When the form is Printed, Only*
Or if this is to be printed, use a Report where the CanGrow setting will work in all views.

For me, the inconsistencies in the various techniques makes most of these approaches not worth the trouble, IMHO.

JeffCoachman
0
 

Author Closing Comment

by:rtod2
ID: 37743339
Thank you sir!  Exactly the info I was looking for.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37743708
Yes, Just to be fair and clear I was not saying that you should not peruse this, ...only that I was trying to make you aware of the inherent limitations...

;-)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

911 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

19 Experts available now in Live!

Get 1:1 Help Now