Solved

Create auto-adjusting notes field

Posted on 2012-03-19
5
287 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 40

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

Title # Comments Views Activity
Access Database 5 47
Access Report Expression 4 27
Access syntax 1 34
Access #Deleted data 20 43
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

730 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