Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expand a text box? 3

Status
Not open for further replies.

ramondrumon

Programmer
Sep 5, 2002
33
US
I would like a text box in form view to expand when it has focus (show 55 characters)and then shrink back (to about 20 characters) when it looses focus. I found the code to make it zoom, but I need to limit the characters to 55 and the zoom box lets you add more letters and then truncates it. Happy Saturday!
 
Not saying this is better, just something else to maybe spark the old creative juices. What if you had a hidden text field that was the expanded lenth you needed and you made it visible and hid the shorter one when it got focus and then reversed the proces on LostFocus.

If the underlying field in the table is defined to be 55 characters then the bound form control will automatically pick that limit up for you.

Good Luck!

PS. I would be interested in seeing how you zoomed the control. I have some ideas but have never had to do that. Please remember to give helpful posts the stars they deserve! This makes the post more visible to others in need![thumbsup]
 
Thanks for that idea, I had not thought along those lines, I wonder if there is a front door approach though. I opened up the zoom box with:

DoCmd.RunCommand acCmdzoomBox.

Thanks for the reply.
 
If you set KeyPreview to yes in the form properties and then do something like this in the form Keydown event, would that work:

Private Sub Form_KeyPress(KeyAscii As Integer)
If Me.CurrentControl = ExpandedTextboxName And _
Len(ExpandedTextboxName) >= 55 Then 'Pasted in??
ExpandedTextboxName = Left$(ExpandedTextboxName, 55)
KeyAscii = 0
End If
End Sub

Good Luck! Please remember to give helpful posts the stars they deserve! This makes the post more visible to others in need![thumbsup]
 
That is more what I was looking for, I am going to work with it!! That idea is worth a star!!
 
There are a number of ways to produce a Zoom of the text box:

1. In the OnGotFocus Event of the text control place the following VBA code: SendKeys "+{F2}" This will zoom the text box with an OK and a Cancel button.

2. Put the following in the OnGotFocus event procedure: MsgBox("Press (Shift + F2) to Zoom this data field.", vbOKOnly, "Zoom Advisory")

3. This option allows you to control the editing and properties of the text control at the time of entry. This example modifies the size of a control that has a Left location on the form of 1" normally. We are going to expand it to 3 inches with code and then return it to 1" upon leaving the control. You do this by modifying the Width property by changing its value to TWIPS(1/1440"). Place this code in the OnGotFocus of the control:
Me![ControlName].Width = 4320
Me![ControlName].SetFocus
Me![ControlName].SelLength = 0
Me![ControlName].SelStart = Nz(Len(Me![ControlName]), 0) + 1
This code also places the cursor behind any already existing data in the control rather than highlighting the text string.

Place this code in the OnLostFocus event procedure:
Me![ControlName].Width = 1440

Any control can be moved and modified by changing the Top, Left, Height, and Width properties through VBA code by modifying adjusting their TWIP values. A TWIP value is 1/1440 of an inch. So if a control has a LEFT property of 1" then its TWIP value for that location is 1440. If the Width is also 1" and we want to expand the control to 3" then we modify the property of the controls Width property to 4320 or (1440 * 3). This is done in the OnGotFocus and then modified back to 1440 TWIPs or 1" in the OnLostFocus events.

I have at times provided an Expand and Shrink button for Memo field controls so that the User can expand the control for ease in reading and entry when then need it but don't require the use of all of that space during normal viewing of the screen.

By leaving the controls Input Mask properties in tact and just expanding the control then you can maintain your control on the number of characters the user may enter.

If this has confused you completely please get back with me and I can add more examples.

Bob Scriver
 
Excellent explanation and examples. Thanks Bob! Please remember to give helpful posts the stars they deserve! This makes the post more visible to others in need![thumbsup]
 
SBendBuckeye: Thanks for the nice comments. Being an MSU Spartan I have noticed your name a number of times in other threads and wondered about that combination. South Bend and a Buckeye!!! Wow. What a combination. Bob Scriver
 
At least you can't cost us a possible NC this year. And there aren't very many of us in South Bend either.

Have a great day! Please remember to give helpful posts the stars they deserve! This makes the post more visible to others in need![thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top