controls to position subforms on the parent form

Danmop

New member
Local time
Today, 18:07
Joined
Jul 24, 2009
Messages
4
Hey folks - Anyone have an answer to this?

I have several subforms that open on a main form. The height for each of the subforms are set based on the number of records in that subform. What I'm trying to do is position each the subforms on the mainform so that none overlap each other.
Problem is I cant find the proper control for each of the forms to position them on the main form, I can get the height of each form, which are based on a "twips" measurement. How do you set the top postion of the subforms?

here is some of the code I have so far:

'Main Form
Private Sub Form_Open(Cancel As Integer)
Dim x As Integer, y As Integer, z As Integer
Dim Hgt As Integer

Hgt = 500
'These globals ExpHgt,WklyHgt,SavHgt can be seen here: all have values
x = ExpHgt
y = WklyHgt
z = SavHgt

'This sets the height of the main form so all the subforms can fit within it
Me.InsideHeight = Hgt * 2 + x + y + z + Me.FormHeader.Height + Me.FormFooter.Height

'This works.. so I know my syntax is right
Me![FRM_SAVINGS].Form.Visible = True

'trying to set postion of bottom form: This dont work - object defined error on .Top
Me![FRM_SAVINGS].Form.Top = x + Hgt + y + Hgt

End Sub

'one of my subforms - FRM_SAVINGS
Private Sub Form_Open(Cancel As Integer)
Dim RecCnt As Integer, Hgt As Integer
Hgt = 500

RecCnt = Me.RecordsetClone.RecordCount
'Set the height of the form
Me.Form.InsideHeight = Hgt * RecCnt + Me.FormHeader.Height + Me.FormFooter.Height

'Post the height on the global variable
SavHgt = Me.Form.InsideHeight

End Sub

The .Top control is not available, thought of using .grid y, but thats on a different measuring system and wont work on the main form anyway.
Any ideas to fix this issue?

- Thanks :cool:
 
If I read this correctly, you're trying to set the position of the Form that being used as the basis of your Subform Control. You need to be setting the Top and Left values for the Subform Control itself, which is to say the container that holds you forms. The Control itself will have Top and Left available.

Linq ;0)>
 
Ok, thats what I was trying to do, obviously Im not referencing the subform controls correctly or I wouldnt be getting the user defined error.
In the main form, I have the code Me![FRM_SAVINGS].Top = ..., where Me is the parent form, and [FRM_SAVINGS] was the subform.
Can you show me the correct syntax to reference this subform control as you said?

Thanks for the reply - appreciate your help on this code

D
 
[FRM_SAVINGS] would need to be the name of the subformcontrol. You are perhaps using the name of the form object that is displayed in the subformcontrol.
 
...I have the code Me![FRM_SAVINGS].Top = ..., where Me is the parent form, and [FRM_SAVINGS] was the subform.
Can you show me the correct syntax...
To explain, hopefully beyond any doubt, what GalaxiomAtHome just said, if FRM_SAVINGS is the Name of the Subform Control you have the correct syntax! But the Name of the Subform Control is not necessarily the same as the Name of the Form the Subform is based on!

Sometimes they share the same Name and sometimes they don't. To determine the actual Name of the Subform Control, in Form Design View,
  1. Right Click on the middle of the top frame of the Subform Control
  2. Click on Properties to bring up the Properties Box
  3. In the Title Bar of this box you should see the words Subform/Subreport followed by the Name of the Form the Subform is based on
If you do not see the words Subform/Subreport in the TitleBar you have not selected the Subform Control and you need to try to select it again. Once you do see these words, you've selected the Subform Control itself! Now, whatever appears to the right of Subform/Subreport : is the actual Name of the Subform Control and this is what needs to appear in the

Me![SubformControl].Top =

statement.

Linq ;0)>
 
ah - I can see what you're saying now. Clicking on the upper left box of the Subform to see the properties - Top is not listed in there. but if i click on the frame of the subform, I see the "subform" reference and a different set of properties that does have the Top, left, etc controls. Ok, both properties have the same name, so after a little expermenting I found the following functional code in the parent form:
me![FRM_SAVINGS].xxx lets me reference the subform's general properties
[FRM_SAVINGS].xxx lets me reference the subform control properties

I was suprised that this worked that way - I thought you always had to reference the parent form before the subform. Well, the whole thing is lining up perfect now, no matter how I distribute the records among the forms.

Thank you for all the help!
 
...I thought you always had to reference the parent form before the subform...
Yes and No!

If you're referencing something on the Form that is the basis of the Subform Control, then Yes, you have to reference the Parent Form first.

If you're referencing the Subform Control itself, which is to say the container that holds the Subform, then No. The Subform Control is simply a Control on the Main or Parent Form itself, and like any other Control on the Main Form can be referenced using Me. as in Me.SubformControlName.

When I create a Subform Control the first thing I do is change is to go into its Property Box and change its name to something other than the one Access gave it. Actually, I usually change all Access-generated names! They tend to confuse rather than clarify things!

Linq ;0)>
 
Yeah me too. I change any access-generated name that I need to interact with. Well thanks again for clairifying Linq. appreciate the help.

D
 
I came across this code sample today trying to find some tips on positioning subforms.

I've never seen this type of code run on a form but it's exactly what I need

I see you have globals assigned to the x, y and z integers that "can be seen here".......Are these controls in the subforms? How and what types of values do you store for them?

I beleive I can test this concept in my database

The variable I am also looking for is the two subforms I am using are hidden if they have no data using a with statement of the mainform; there are instances that my mainform will not display either of these subforms, one of the two, or both.....I need to position a top spot and a 2nd top spot of the mainform for the subforms to fill if one is displaying data and if two are displaying data. If one of the two are displaying, I'd like it to be in the top spot no matter which subform it is, and if both are displaying, I'll pick subform 1 always gets the top spot and subform 2 can take the 2nd top spot

Any ideas to accomplish this??????
 
If I read this correctly, you're trying to set the position of the Form that being used as the basis of your Subform Control. You need to be setting the Top and Left values for the Subform Control itself, which is to say the container that holds you forms. The Control itself will have Top and Left available.

Linq ;0)>

I was wondering if you might be able to assist me as you understand that a subform has a form and a container. Each might have the same or different name and one has a .top property (container) and the other does not (the form.) I would also add that in my case I have the subform in a further container known as a Tab Control.

Now, I found a very useful utility on these pages that enables me to place a button/label and on the click of the button/label the form hides or reveals parts of the form. It seemed to work perfectly in Access 2010 but I'm now required to use Access 2016. What this causes is that for any subform that is in the Tab Control the subforms container moves and repositions correctly but it leaves all the fields of the form at the originally position..

My question is have you seen this behavior and do you know of a work around? THanks much in advance for any and all assistance you provide.:banghead:
 
I'm using Access 2013 but in my experience I have noticed that when placing controls etc. onto a Tab control the tab will light up to indicate I am actually placing the new control onto the Tab control and not just into the form somewhere. Furthermore, I have also noticed that if ever I wish to Copy/Paste an existing control that I already know to be associated to the tab control, after I CTRL+C, if I don't select an item (any item) already associated to the tab before pasting, the pasted items will NOT be associated to the tab control and thus will NOT move with it when it moves.
 

Users who are viewing this thread

Back
Top Bottom