?
Solved

Create auto-adjusting notes field

Posted on 2012-03-19
5
Medium Priority
?
291 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 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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

621 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