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!

On Format Event - CanGrow ?

Status
Not open for further replies.

Vittles

Programmer
Dec 7, 2000
95
US
I have an on Format event that changes the font style/size depending on the value of a field. It works very well, but the control is not growing to fit the contents, even though the 'cangrow' property (for both the detail section & the textbox) is set to yes. I am using Access 2003. Do I have to add that property to the on Format event coding (listed below)? If so, how do you do so?

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.[KP Country] <> "USA" Then
Dim strFirst As String
Dim strLast As String
Dim intLeft As Integer
Dim intTop As Integer
strFirst = Left(Me.Current_City_Country, InStr(Me.Current_City_Country, "(") - 1)
strLast = Mid(Me.Current_City_Country, InStr(Me.Current_City_Country, "(") + 1)
Me.CurrentX = Me.Current_City_Country.Left
Me.CurrentY = Me.Current_City_Country.Top
Me.FontBold = True
Me.FontSize = 9
Me.Print strFirst & " "
Me.FontBold = False
Me.FontSize = 8
Me.CurrentY = Me.Current_City_Country.Top
Me.Print "(" & strLast
Else
strFirst = Left(Me.Current_City_Country, InStr(Me.Current_City_Country, "(") - 1)
Me.CurrentX = Me.Current_City_Country.Left
Me.CurrentY = Me.Current_City_Country.Top
Me.FontBold = True
Me.FontSize = 9
Me.Print strFirst
End If
End Sub
 
Did I read somewhere that cangrow is for reports and does not work on forms?
 
The property works fine in reports and forms.

You are not using the property at all by using the Print method. Print has nothing to do with the "Can Grow" property. My guess is that you really wanted to have the font in Current_City_Country to be changed but you could not work out how to do it so reverted to printing instead?

If you want to change the font at runtime on a report, you need to use the following method.

Code:
Me.Current_City_Country.Properties("FontSize")=9

If you are ever unsure as to what properties are available, just put a break point in your code and whack a line like the following in the immediate window. Works a treat

Code:
for c = 1 to Me.Current_City_Country.Properties.Count : ? Me.Current_City_Country.Properties(c).name,Me.Current_City_Country.Properties(c): next
 
I should have been more specific. I actually have one textbox that contains 2 different font sizes & styles (bold/not bold) of text depending on the country value.

If the country is USA then we do not want the city/country values listed at all [ex: Institution Name] with only one font.

If the country is not USA then the Institution is bolded and the city & country is listed but in a smaller font & not bolded [ex: Institution Name (city, country)].

The formula in the textbox is:
=IIf([KP Country]="USA",[KP Current Institution] & "(",[KP Current Institution] & " (" & [KP City] & ", " & [KP Country] & ")")

The coding and textbox work as they show the proper values and the right fonts. The only part I can't seem to figure out is how to make this happen & still have the ability for the textbox to have the CanGrow property work as these values are being cut off after they exceed the textbox length instead of just wrapping to the next line.

Any ideas would be great. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top