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>

EqupiAssigntoNewLocnLHS  EqupiAssigntoNewLocnRHS

(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
        End If
        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
            End If
        End If
    Next

(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.

<sigh>

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.

Published Thu, Mar 19 2009 23:08 by Tony

Comments

# re: A brilliant idea that didn't work - moving a group of controls in a tab control

It seems from your discussion that there's always an "Issue to New Location" subform, but there may or may not be a "Return Equipment" subform.

In this situation, I'd switch the positions of the two subforms, so that "Issue to New Location" is on the left.  It also matches the flow of the information, because you have to Issue it, before you Return it.

Stan

Friday, March 20, 2009 12:48 PM by Stan Scott

# re: A brilliant idea that didn't work - moving a group of controls in a tab control

My first suggestion would fix the left-right issue, but there's still be a lot of space.

This idea might work.  You have three tabs, one for each subform, and there are three "holes" where the tabs live.  Let's assume they're named "hole1", "hole2", and "hole3".

In your code, you can set the .SourceObject property of each one to the desired tab, which will let you close up any gaps.

Friday, March 20, 2009 12:55 PM by Stan Scott

# re: A brilliant idea that didn't work - moving a group of controls in a tab control

Stan.  

Your first paragraph is correct.  

However the user should be returning the equipment before you issue it.  So I don't want to disturb that left to right flow.

Friday, March 20, 2009 2:58 PM by Tony

# re: A brilliant idea that didn't work - moving a group of controls in a tab control

re: Moving tab controls.

Our solution in our ShrinkerStretcher product was to calculate the correct new location and size of the tab control, then move the controls, then incrementally move and size the distorted tab control, bit by bit, to its correct location and size. For your purposes, it would seem to be much simple just to put your controls in a subform control and move the subform control.

All the best,

Peter De Baets

http://www.peterssoftware.com

Sunday, March 22, 2009 2:01 PM by Peter De Baets

# re: A brilliant idea that didn't work - moving a group of controls in a tab control

Fellow Access MVP A.D. Tejpal worked on this problem.  

His sample db named Form_MoveTabControl is now available at Rogers Access Library. Link -

www.rogersaccesslibrary.com/.../forum_topics.asp

   It demonstrates re-location of tab control to any desired position, along with all its controls on various pages, without using any custom built collection or array.

   You might like to test it out extensively so as to verify successful working under all possible circumstances. Moving the tab control from top left position to bottom right seems to represent the most tricky scenario, requiring special handling, as shown in the sample db.

Tuesday, March 24, 2009 2:33 PM by Tony

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: