A brilliant idea that didn't work - moving a group of controls in a tab control
I created an unbound form in the Granite Fleet Manager assigning equipment to a new location such as a construction job site or fire trucks assigned to a different county to help with brush fires. If the equipment is already assigned to a location(s) then a subform is displayed showing all the locations along with some unbound fields and a command button to flag the equipment as having been returned from the job site(s). See the left hand screen show below.
However if the equipment isn't currently issued to a location then only the unbound fields including location and a command button are displayed on the form. See the right hand screen shot below. That form looks quite unbalanced and not visually esthetic. Not, you understand, that I'm overly worried about esthetics but hey. <smile>
(You can click on the forms to expand them if desired.)
First I created a few lines of code to move the right hand controls up and to the left.
Const TwipsLeft As Long = 2880, TwipsUp As Long = 1440
For Each ctl In Me.Controls
If InStr(ctl.Tag, "ReturnEquip") > 0 Then
ctl.Visible = DisplayReturnEquipment
If InStr(ctl.Tag, "AssignToNewLocation") > 0 Then
ctl.Visible = DisplayNewLocation
' Shift the Display New Location fields up and to the left
If DisplayReturnEquipment = False And DisplayNewLocation = True Then
ctl.Left = ctl.Left - TwipsLeft
ctl.Top = ctl.Top - TwipsUp
(The ctl.visible = lines use the strings I placed in the controls Tag property to decide when the controls are visible or not.
There are 1440 twips to the inch. )
In the above code you can see how I used the controls left and up properties to move the control around.
This would've worked just fine if I closed the form after the user executed the command button. However I allow the user to select a new unit in the combo boxes. And now I have to move the controls back to where they were. The only way I could think of doing this was do save the original top and left positions of each control in an array or collection of some sort.
So I dug out the Access Developers Handbook and started to go through the Controlling Forms chapter. I saw an interesting heading titled Using the Tab Control as a Container. Aha. And there's the answer. Copy those fields onto a tab control. Set the tab controls Style property to None and, if required, set the Back Style to Transparent.
Now I just need to save the tab controls Top and Left property on opening the form and move the tab control up and to the left when required.
This will also come in very handy when I add more subforms to the equipment and/or service order forms. I'' be running out of room on the single row of tabs. I'm going to implement a list box on the left hand side of the form to control which tab the user will view. Continuing to use the tab control will be handy for me to group the controls. However I don't want the tabs to be visible to the user.
But the code moving the tab control didn't work.
When, after executing the code, using debug I displayed the top and left values of the tab control the new values showed the tab control had shifted. But I could see that it hadn't moved. Furthermore Task Manager showed one of my two CPUs in my laptop was pinned at 100% until I closed the form.
When I tested the code on a label it moved just fine.
So I, finally, created a new MDB with a form and some simple controls just to test this. Well the tab control did move in my example. However the controls placed on the tab control did not move. Furthermore Access left the lower right hand corner of the tab control where it was to ensure the embedded controls stayed on the tab.
A brilliant idea that didn't work. I spent hours and hours trying to figure out the problem before I created the test MDB.
So now I have to store each individual controls name, top and left coordinates in either a two dimensional variant array or possibly a collection. A collection looks like it's more trouble than it's worth so I'll just use an array.