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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cangrow property 1

Status
Not open for further replies.

SueRobbins

Programmer
Nov 12, 2001
13
US
I've used the "cangrow" property successfully on fields in report detail areas, but am having a problem making it work on a field in the detail area of a form. I'd like the field to grow vertically, but it just appears to be truncated, even though cangrow = "Yes".

Anything else I should be looking for relative to this?
 
I am afraid CanGrow has some 'buts':
Microsoft said:
These properties affect the display of form sections and controls only when the form is printed or previewed, not when the form is displayed in Form view, Datasheet view, or Design view.

It is possible to 'grow' a control through code.
 
How are ya SueRobbins . . .
Microsoft said:
[blue]You can use the CanGrow/CanShrink properties to control the appearance of sections or controls on forms and reports that are [purple]printed or previewed.[/purple][/blue]
A report doesn't have an [blue]Report View[/blue], it has an [blue]Print Preview[/blue] . . . [purple]Form View[/purple] is not a preview!

Calvin.gif
See Ya! . . . . . .
 
Am comfortable with coding, but need some direction. Assume I have to first figure out how "tall" the field needs to be (based on the value and the font), then set the height property of the field, right? How do you calculate this?

Thanks in advance for any help.
 
This may suit best:
DoCmd.RunCommand acCmdZoomBox
It means that you do not have to change the design of your form or leave room for a growing box. It can be run in a suitable event.
If you would still prefer to 'grow' your control, please say.
 
SueRobbins,
You might find this thread interesting, it covers a couple of different approaches.
[navy]Microsoft: Access Forms Forum:[/navy] thread702-1207991 [navy]form display problem[/navy]

CMP

(GMT-07:00) Mountain Time (US & Canada)
 
CautionMP,

Thanks very much. I think the height calculation in the thread you referenced is just what I need. Another question now:

My form is tabular; i.e. one row for each record. Ten fields are being displayed in the detail area, three of which can potentially "grow". How exactly do I invoke the height calculation and set the height property? On what event?
 
SueRobbins,
In my opinion that's the hardest question to answer since I feel it depends on how the form will be used, how you (or the user) want the form to look/work, the time you have to invest in development, and your skill level. With that said, here are a couple of thoughts:
[ol]
[li]If the form is primarily used to read the data in the form you could use the [tt]GotFocus()[/tt] event for each of the three controls that could grow, this way the control will resize when the user clicks on it.
Code:
Private Sub [i]ControlName[/i]_GotFocus()
  If Len(Me.[i]ControlName[/i].Value) > [i]LengthOfDefaultField[/i] Then
    Me.[i]ControlName[/i].Height = (Len(Me.[i]ControlName[/i].Value) \ [i]CharactersPerLine[/i] + 1) * ([i]StandardRowHeightInInches[/i] * 1440)
  Else
    Me.[i]ControlName[/i].Height = [i]StandardRowHeight[/i]
  End If
End Sub
[/li]
[li]If the data in the three fields will be changed you could use the [tt]Exit()[/tt] event of the three controls causing the controls to resize when the user moves to the next field.
Code:
Private Sub [i]ControlName[/i]_Exit(Cancel As Integer)
  If Len(Me.[i]ControlName[/i].Value) > [i]LengthOfDefaultField[/i] Then
    Me.[i]ControlName[/i].Height = (Len(Me.[i]ControlName[/i].Value) \ [i]CharactersPerLine[/i] + 1) * ([i]StandardRowHeightInInches[/i] * 1440)
  Else
    Me.[i]ControlName[/i].Height = [i]StandardRowHeight[/i]
  End If
End Sub
[/li]
[li]If you really want to pull your hair out, you can make the field change as the user types by using the [tt]KeyUp()[/tt] event.[/li]
[li]Lastly, you could run a routine when the form loads to set the initial size of the three controls based on the underlying record set, and then never change them.[/li][/ol]

Keep in mind that as a continous form, everytime you change the height of a control, the height of that control will change for every record that is displayed on the form.

That should make it clear as mud,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
CautionMP,

The good news is that I did understand your explanation. It was very clear and thorough.

The bad news is that my form is continuous and none of the fields are enterable, so I won't be able to accomplish the look that I want. Your last sentence says it all: "Keep in mind that as a continous form, everytime you change the height of a control, the height of that control will change for every record that is displayed on the form."

I was hoping to get the same look as a printed/previewed report where each row's height is a function of the "tallest" control on it.

Thanks anyway. I'm learning a lot!



 
Perhaps you can still work it:
Code:
Private Sub Form_Load()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
intLongest = DMax("Len(Trim(Field2))", "tblMemo")
intCharsPerLine = 53
intLines = intLongest \ intCharsPerLine
'say 200 twips per line
Me.Field2.Height = intLines * 200
End Sub
A little substitution of CautionMP's code to make it better, and you may have something that suits.
 
Thanks, Remou, but your suggestion causes all rows to be the same height; i.e., the hight of the longest instance of Field2. As CautionMP correctly pointed out, changing the height of a control causes the height of that control will change for EVERY record displayed on the continuous form.

I'm resigned to setting the height in design mode to something appropriate for the majority of records.
 
SueRobbins,
[navy]Remou[/navy] has you on the right track for option 4.

If your feeling real adventurous, you could make your form work that way. You have 10 fields per record to display, lets say for the sake of discussion you want to display 5 records at a time. Create a form with 50 controls with a line drawn between each group of 10.
Build a 'cursor' mechanism to load the data from 5 records into the 50 controls, moving and resizing as necessary.
You then build Event handlers for both mouse movement and keyboard key presses that moves the 'cursor' the appropriate direction in response to the user input.

It can be done, but is it worth it? Only you can answer that question.

My motto: Just because it can be done, doesn't mean it's a good idea. But until you try, how will you know?

CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top