Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Grow a text field on a form, possible?

Is it possible to grow a text field on a form?  I know you can on a report but I don't seem to be able to make it happen on a form.
Avatar of Bill Prew
Bill Prew

There is no built in way to do this with say a TextBox control on an Access Form.  A couple of thoughts though since I don't know the exact use case you have in mind.

If you only need to do this when the form is opened, and not dynamically as data is entered, then you might be able to use the CanGrow property of the TextBox.  But you will have to dynamically add that field to the form when the form opens, you can't set it on a control you placed using the form designer.

If you are looking to do it real time based on data typed into the field then a couple of thoughts.

One would be rather than change the size of the field, you could change the fond size.  So have an event that reacts to changes to the content of the field and when it exceeds a certain length in number of characters you drop the font size down on that field.  It won't be perfect since you're likely working with variable pitch fonts, but it might be an approach.

Another approach if you want it dynamic based on what they enter would be to monitor changes with and event and adjust the Width property of the control based on content.  The challenge here is deciding what to set the width to in pixels based on the corrent content length in characters.  I had to come up with a function to calculate the width in pixels from the content knowing the font name and size and as I recall it was pretty tricky.  But in theory it's an approach.


»bp
Avatar of SteveL13

ASKER

How would I dynamically add that field to the form when the form opens?
This was the prior question I was thinking of, and upon re-visiting it there are a number of differences to what you are doing.  It was in Excel, and with controls placed right on the worksheet rather than a form, etc.

Set font smaller and allow box to expand

I played around a bit in Access, but even following some of MS docs I can't seem to add a control to an existing form at runtime.  I'm probably missing something, but don't have the time right now to do a deeper dive into it.

Sorry I wasn't more help quickly, maybe another expert will have some creative ideas.


»bp
Apparently there may be no solution to this issue.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.