Solved

Create auto-adjusting notes field

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views 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 Access…

746 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

13 Experts available now in Live!

Get 1:1 Help Now