VBA to set height of text box on a report (1 Viewer)

Snowflake68

Registered User.
Local time
Today, 08:08
Joined
May 28, 2014
Messages
452
I have a report list has outlined text boxes which are all lined up nicely to also show the total and the VAT etc. The list of items on the report have which auto resize when the item description increases and decrease.

Code:
Dim numDescHeight As Integer

numDescHeight = txtDescription.Height

txtUnitPrice.Height = numDescHeight

I have tried the above so that when the description auto resizes I want the UnitPrice height to be set to the same height but I get error 424 object required.

I have double checked the names of the text boxes and they are both correct.

Any ideas?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:08
Joined
Sep 12, 2006
Messages
15,656
Which line is it failing at?
If you have onerror resume next, comment it out, as you need to understand where it is failing.

Assuming it's failing at txtDescription, try replacing that with me.controls("txtdescription").height
Maybe the same with txtUnitPrice.

Also you might need this code in the onFormat or the onPrint events, otherwise it may not error, but it may not work either.
Without testing., I am still not sure if you can do it this way. I don't know if the textbox control is aware of the height of the data it contains.
 
Last edited:

Snowflake68

Registered User.
Local time
Today, 08:08
Joined
May 28, 2014
Messages
452
Which line is it failing at?
If you have onerror resume next, comment it out, as you need to understand where it is failing.

Assuming it's failing at txtDescription, try replacing that with me.controls("txtdescription").height
Maybe the same with txtUnitPrice.

Also you might need this code in the onFormat or the onPrint events, otherwise it may not error, but it may not work either.
Without testing., I am still not sure if you can do it this way. I don't know if the textbox control is aware of the height of the data it contains.
It error at this line
numDescHeight = txtDescription.Height

but I will try your other suggestions to see if any of them work.

Thanks
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:08
Joined
Sep 12, 2006
Messages
15,656
What error code and message does it actually give you?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:08
Joined
Feb 28, 2001
Messages
27,186
What error code and message does it actually give you?

Dave: In the first post, "424 Object Required."

@Snowflake68 - Thinking about this error, the ONLY object to which it could be referring is txtDescriptions, the qualifier of "txtDescription.Height"

If you put this into debug mode when you get that error, open up the Immediate window. You should be able to type this:

Code:
Debug.Print  txtDescription.Height

It will tell you one of two things: a number (the current value of .Height) or NULL - meaning that txtDescription is not currently instantiated. I'm not sure why it wouldn't exist, but it would explain that particular error.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:08
Joined
Sep 12, 2006
Messages
15,656
Dave: In the first post, "424 Object Required."

@Snowflake68 - Thinking about this error, the ONLY object to which it could be referring is txtDescriptions, the qualifier of "txtDescription.Height"

If you put this into debug mode when you get that error, open up the Immediate window. You should be able to type this:

Code:
Debug.Print  txtDescription.Height

It will tell you one of two things: a number (the current value of .Height) or NULL - meaning that txtDescription is not currently instantiated. I'm not sure why it wouldn't exist, but it would explain that particular error.

Yes, but if you just opened the form and clicked the the OP's help button, you got the OP's "error message" which wasn't accurate, and the error code was actually the one for "no previous control"

If you clicked the other button and then clicked the help you got the error 424 you mentioned, hence my syntax comment in #2. I didn't look further, and as I said, I am not sure whether you can get the height at all. I know Steven Lebans had code to successively reduce a font size to a size where text fitted inside a text box, which is a slightly different solution. (I think that was the idea - it was a long time ago)
 

Users who are viewing this thread

Top Bottom