Subform Setting

C

Chipcom

Hi

I would like to know how to cause that the subform can not be on
focus?
I would like to know how to shrink and grow automatically?

Thanks
 
S

Steve Schapel

Chipcom,

To prevent access to the subform, set the Enabled property of the
subform to No.

As for shrinking and growing, I assume you mean a continuous view
subform whose height is adjusted according to the number of records. Is
that right? If so, you would need to write some VBA code to change the
height of the subform control, to a value that is calculated by
multiplying the number of records by the height of the Detail section of
the subform. If there were controls on the form which are underneath
the subform, and you wnat also that their position is adjusted according
to the height of the subform, then this would require more code to
adjust the value of their Top property. It can be done. The code would
probably need to run on the Current event of the main form.
 
C

Chipcom

Chipcom,

To prevent access to the subform, set the Enabled property of the
subform to No.

As for shrinking and growing, I assume you mean a continuous view
subform whose height is adjusted according to the number of records. Is
that right? If so, you would need to write some VBA code to change the
height of the subform control, to a value that is calculated by
multiplying the number of records by the height of the Detail section of
the subform. If there were controls on the form which are underneath
the subform, and you wnat also that their position is adjusted according
to the height of the subform, then this would require more code to
adjust the value of their Top property. It can be done. The code would
probably need to run on the Current event of the main form.

--
Steve Schapel, Microsoft Access MVP






- Show quoted text -


Can you please show me an example how to write a code to adjust the
height of the subform (The subform view is datasheet)?

You said : "set the Enabled property of the subform to No" - But what
is the Enabled property?

Thanks
 
S

Steve Schapel

Chipcom,

Re the Enabled property... In the design view of the main form, select
the subform, and then open the Property sheet. You will see the Enabled
property listed, with possible settings being Yes or No.

Sample code:

Dim subHeight As Long
Dim subRecords As Integer
subRecords = DCount("*", "YourQuery") + 1
subHeight = Int(((0.58 * subRecords) + 1) * 567)
If subHeight > 7655 Then
subHeight = 7655
End If
Me.YourSubformName.Height = subHeight

In this example:
YourQuery = then name of the query that the subform is based on.
0.58 = the height of the Detail section of the subform in centimetres.
567 = the number of twips in a centimetre.
7655 = the maximum height (in twips) for the subform.
YourSubformName is the actual name of the subform control.

I would recommend using a continuous view form for the subform, rather
than datasheet.
 
Top