I need a function similar to the TextWidth method of report objects but which will work on a form. I need to break text up into lines for a form display similar to what we already do on a report. Unfortunately, forms don’t have a TextWidth method, at least no in A97.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Form Equivalent of TextWidth (97 SR1)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Form Equivalent of TextWidth (97 SR1)
- This topic has 9 replies, 4 voices, and was last updated 22 years, 5 months ago.
AuthorTopicWScharlotte
AskWoody LoungerDecember 17, 2002 at 7:11 pm #380836Viewing 1 reply threadAuthorReplies-
WSHansV
AskWoody LoungerDecember 18, 2002 at 7:09 am #639457Charlotte, the attached module contains a function GetTextWidth. This function returns the text width (in twips) of the text in the active control. You can use it (for instance) in the OnChange event of a text box.
The code is derived from the code provided in MSKB article ACC: How to Limit Number of Characters to Size of Text Box.
-
WScharlotte
AskWoody LoungerDecember 18, 2002 at 1:10 pm #639505Thanks, Hans. I had already looked at that code in the MSKB before I posted. The problem with it is that it assumes the control will have the focus and gets the hWnd for that control. What I’m doing is filling in a *series* of unbound form controls with text that may be chunks of a string too big to fit into a single control from a single record or may be a series of strings from sequential records. For sufficient reasons the controls are not necessarily the same width. I adapted a method from the Access Developers Handbook for A97 used for sizing controls to fit their contents. I just used the relevant portion to determine the length of the text in twips based on the font size and compared it to the width of the control in twips. And of course it has to be parsed by word so that no word gets broken at the end of the available space.
-
WSHansV
AskWoody LoungerDecember 18, 2002 at 1:28 pm #639510Charlotte,
The MSKB code needs the control to have focus at two places:
- To get the current text in the control. Since you are breaking up an existent string, you don’t need that; you can pass strings as a parameter instead.
- To get the window handle of the control. To get around this, you could fill an array with the hWnd’s of the controls in OnLoad of the form, and pass the appropriate hWnd as a parameter.
The function could look like this:
Public Function GetTextWidth(strVal As String, hWnd As Long)
‘ Get text width of string in control in twips
Dim hDC As Long
Dim lpSize As Size‘ Get device context of control
hDC = GetDC(hWnd)‘ Compute the width of the text
GetTextExtentPoint hDC, strVal, Len(strVal), lpSize
ReleaseDC hWnd, hDC
ConvertPixelsToTwips lpSize.cx, lpSize.cy
GetTextWidth = lpSize.cx
End Function -
WScharlotte
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WScharlotte
AskWoody Lounger -
WScharlotte
AskWoody LoungerDecember 24, 2002 at 1:18 pm #640646Here’s the code I used. It definitely works with Access 97 but I would be cautious about recommending it for later versions due to the highly explicit declarations from the Msaccess executable itself. The advantage to it is that the controls don’t ever need to get the focus in order to determine the width.
-
WSpatt
AskWoody Lounger
-
-
-
-
-
WSShane Sargent
AskWoody Lounger
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
24H2 has suppressed my favoured spider
by
Davidhs
2 hours ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
6 hours, 8 minutes ago -
MS Office 365 Home on MAC
by
MickIver
8 hours, 7 minutes ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
20 hours, 10 minutes ago -
Flash Drive Eject Error for Still In Use
by
J9438
21 hours, 43 minutes ago -
Windows 11 Insider Preview build 27863 released to Canary
by
joep517
1 day, 15 hours ago -
Windows 11 Insider Preview build 26120.4161 (24H2) released to BETA
by
joep517
1 day, 15 hours ago -
AI model turns to blackmail when engineers try to take it offline
by
Cybertooth
18 hours, 42 minutes ago -
Migrate off MS365 to Apple Products
by
dmt_3904
19 hours, 31 minutes ago -
Login screen icon
by
CWBillow
9 hours, 53 minutes ago -
AI coming to everything
by
Susan Bradley
5 hours, 52 minutes ago -
Mozilla : Pocket shuts down July 8, 2025, Fakespot shuts down on July 1, 2025
by
Alex5723
2 days, 6 hours ago -
No Screen TurnOff???
by
CWBillow
2 days, 7 hours ago -
Identify a dynamic range to then be used in another formula
by
BigDaddy07
2 days, 7 hours ago -
InfoStealer Malware Data Breach Exposed 184 Million Logins and Passwords
by
Alex5723
2 days, 19 hours ago -
How well does your browser block trackers?
by
n0ads
2 days, 5 hours ago -
You can’t handle me
by
Susan Bradley
4 hours, 18 minutes ago -
Chrome Can Now Change Your Weak Passwords for You
by
Alex5723
1 day, 22 hours ago -
Microsoft: Over 394,000 Windows PCs infected by Lumma malware, affects Chrome..
by
Alex5723
3 days, 6 hours ago -
Signal vs Microsoft’s Recall ; By Default, Signal Doesn’t Recall
by
Alex5723
2 days, 10 hours ago -
Internet Archive : This is where all of The Internet is stored
by
Alex5723
3 days, 7 hours ago -
iPhone 7 Plus and the iPhone 8 on Vantage list
by
Alex5723
3 days, 7 hours ago -
Lumma malware takedown
by
EyesOnWindows
2 days, 19 hours ago -
“kill switches” found in Chinese made power inverters
by
Alex5723
3 days, 15 hours ago -
Windows 11 – InControl vs pausing Windows updates
by
Kathy Stevens
3 days, 15 hours ago -
Meet Gemini in Chrome
by
Alex5723
3 days, 19 hours ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
3 days, 20 hours ago -
Trump signs Take It Down Act
by
Alex5723
4 days, 4 hours ago -
Do you have a maintenance window?
by
Susan Bradley
2 days, 8 hours ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
3 days, 6 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.