Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create auto-adjusting notes field

Posted on 2012-03-19
5
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 77

Assisted Solution

by:peter57r
peter57r earned 668 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 664 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 668 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

660 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