Move back textbox (1 Viewer)

LeslyP

Registered User.
Local time
Yesterday, 21:26
Joined
Apr 27, 2018
Messages
34
Hello,

I want to do Something very simple, but....well, it's Access.
I can't find anything on Google.

So, I have some textboxes at a certain place in a form. When the form open, I move those textboxes (There are in the way) with me.textbox.top = 10. I want them to come back at their original place when I click on a button. I don't want to write one by one a new me.textbox.top = ... because I have a looooot of them.

If there is a option like "me.textbox.move = top 10" and "me.textbox.move = top -10", that would be great. (I tried it, but dosen't worked).

Thank you for you help,

LeslyP
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:26
Joined
Feb 28, 2001
Messages
27,223
From VBA there is no single command to do this although it is remotely possible that in layout mode, you could define a box to be a layout block and could move the block (and everything inside it). I've not tried layouts because to me they are a pain in the derriere.

The question is, why do you want the boxes to move? How did they move someplace else in the first place?

I am going to guess that they are disabled at first? Because that's another thing you would have to address if you are trying to make a dynamic form with moving controls. Otherwise they would overlap and then (if not disabled), there is no telling which one is on top. If you have enough of these to move, there is also the issue of crowding and visual overlap.

BTW, the syntax appears wrong for what you suggested because MOVE is a method that acts like a function, not like an expression, The equals sign is incorrect in that context.

Code:
Me.textbox.Move top 10
Me.textbox.move top -10

Further, you can just specify "0" instead of "top" because the top of a section is 0. Similarly, the left-most edge of a section is 0 rather than "left." In fact, the reference I found for MOVE didn't mention a keyword for "top" or "left" edges. And I don't think you can EVER supply negative coordinates for a control. The positions MUST be within the parent section boundaries.

The one time I needed dynamic controls, I approached this with a complex little subroutine where I started with a rectangle (with invisible borders). It was big enough to hold up to about 10 command buttons in two rows of five. Since I had 13 possible buttons but only eight at a time could ever show up (due to mutual exclusion of functions), I knew they would always fit.

Then I had a subroutine that took a command button (ByRef), the rectangle (ByRef), and a boolean (ByValue was ok) as three input arguments. The sub "knew" the last place I had inserted a visible command button so it automatically computed where the next button would have to go. If the Boolean input was true, the button was enabled, made visible, placed inside the box, and the position parameters were updated. If the Boolean input was false, the button was disabled and made invisible. It was placed in the box in the next slot anyway - but the positioning parameters were NOT updated. I.e. disabled+invisible controls were allowed to stack until a visible control was placed on that location.

I am only describing it, not posting it, because (a) I don't own that code any more, my former employer does, and (b) I'm still only guessing at what you really want.
 

isladogs

MVP / VIP
Local time
Today, 05:26
Joined
Jan 14, 2017
Messages
18,246
If the textboxes are in the way when you open the form, then presumably you don't need to see them at that time. So why not hide them by setting the visible property=false.
Then you don't need to move them.

When you click the button, just set visible =true.
 

LeslyP

Registered User.
Local time
Yesterday, 21:26
Joined
Apr 27, 2018
Messages
34
Hello Richard ! Hi Ridders !

Thank you very much for your answer.
So there not such a thing as this "move" I wanted... snif.
The_Doc_Man :The subroutine you described is a little like what I want. Let me explain exactly what I am trying to do.

The_Doc_Man and Ridders
In the header, there is textboxes in a Stacked layout. There a too many of them (Ther header is like half the form), so I change their height to 0 and their visible to False depending on a Yes/No button. The problem is with the Choice buttons. It doesn't want to stacked, so even if I changed height of the textbox on top of it to 0, it stays there.

Do you think of an easy (or not so easy) way of making the Choice buttons move like everything else ?
 

isladogs

MVP / VIP
Local time
Today, 05:26
Joined
Jan 14, 2017
Messages
18,246
Suggest you get rid of the supposedly helpful layout guides that are a total PITA if you try and modify them in any way.
Delete the lot and you'll find it MUCH easier to place your controls where you want...though as I said before, why not just hide them until you need them?
 

LeslyP

Registered User.
Local time
Yesterday, 21:26
Joined
Apr 27, 2018
Messages
34
Ridders:
Because I want my header to be smaller. The header grow and shrink with the layout.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:26
Joined
Feb 28, 2001
Messages
27,223
LeslyP - unfortunately, there IS no simple solution to this. There is no BULK move function or method, only a one-by-one method.

So... how often do your designs include this operation? If this is a one-off form that you will never repeat elsewhere, bite the bullet and repeat the move operation once for each affected control. If this concept is something you need to do often, spend some time designing a subroutine for a general module and you can then just have a list of calls that do everything at once.

I'm going to add a comment that Ridders overlooked. It is not enough to make a box not visible. It can still be enabled and thus take effect if you happen to click in it. You have to not only hide boxes, you have to disable them too. The effect that you want to avoid is that you have a bunch hidden, stacked controls and accidentally click into one of them. And you won't even know which one you hit because which one is on top kind of varies depending on the order they were built (I think). But you'll hit whichever one is on top of that stack. Which is why doing this is an incredibly complex thing to do.

As to those "choice" buttons... Are we talking about a bunch of Toggle Buttons (Option Buttons) only one of which can be selected at any one time in the Option Group? You have to move the whole group in that case, I think.

Concur with Ridders: Using a Layout box is an incredible pain to work with using VBA. Structurally they add another layer of complexity and they are hard as hell to move around. That's why I avoided them like the plague. They are the one thing about using form wizards that I really didn't like.
 

isladogs

MVP / VIP
Local time
Today, 05:26
Joined
Jan 14, 2017
Messages
18,246
LeslyP - unfortunately, there IS no simple solution to this. There is no BULK move function or method, only a one-by-one method.

So... how often do your designs include this operation? If this is a one-off form that you will never repeat elsewhere, bite the bullet and repeat the move operation once for each affected control. If this concept is something you need to do often, spend some time designing a subroutine for a general module and you can then just have a list of calls that do everything at once.

I'm going to add a comment that Ridders overlooked. It is not enough to make a box not visible. It can still be enabled and thus take effect if you happen to click in it. You have to not only hide boxes, you have to disable them too. The effect that you want to avoid is that you have a bunch hidden, stacked controls and accidentally click into one of them. And you won't even know which one you hit because which one is on top kind of varies depending on the order they were built (I think). But you'll hit whichever one is on top of that stack. Which is why doing this is an incredibly complex thing to do.

As to those "choice" buttons... Are we talking about a bunch of Toggle Buttons (Option Buttons) only one of which can be selected at any one time in the Option Group? You have to move the whole group in that case, I think.

Concur with Ridders: Using a Layout box is an incredible pain to work with using VBA. Structurally they add another layer of complexity and they are hard as hell to move around. That's why I avoided them like the plague. They are the one thing about using form wizards that I really didn't like.

Doc
You must be using a 'special' version of Access as hidden textboxes cannot be clicked on even if you arrange them to be at the front/top of the pile.
I didn't 'overlook' that issue. There is no need to disable them as well which is why I didn't mention it.
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 05:26
Joined
Feb 19, 2013
Messages
16,629
So there not such a thing as this "move" I wanted... snif.
only way you could do it with one vba command is to put your controls in a subform, them move the subform

but a simple bit of code can be used so your code loops through the controls. identifies them and moves them appropriately. It's basic maths

You need to determine the maths of where the top is required to be - is it related to the bottom of the header section? the top? And similarly for the left - perhaps related to the control to its left?

Assuming your button tag property is populated with 1, 2 etc (the order you want then to appear) and the width required is 2cm (1134 twips), height is 0.5 com (283 twips) and the spacing is 60 twips then use something like

Code:
dim ctrl as control
for each ctrl in me.section(1).controls
    if not isnull (ctrl.tag) then ctrl.move (ctrl.tag-1)*(1134+60)+60,section(1).height-ctrl.height-283-60,1134,283
next ctrl
 

moke123

AWF VIP
Local time
Today, 00:26
Joined
Jan 11, 2013
Messages
3,927
While I understand your question as far as moving controls around the form, I'm not sure its clear why.
Could you describe what your Database is about and how the form relates to it.
What is the process involved that necessitates moving controls?

As doc mentioned Option Groups, That is a method I have used in the past but without the need to move anything. With an option group you can change the captions of the controls and hide and unhide as needed. The value of each button remains unchanged (1,2,3,etc) and you just use select case statements in your code as needed.
 

LeslyP

Registered User.
Local time
Yesterday, 21:26
Joined
Apr 27, 2018
Messages
34
Oh my God, so many answers. Thank you. I thought it would be really easy....Sorry o.o"

I don't want to waste everyone's time with that :S I think I'll just make everything smaller. It's not the better option, but damn. It's too complicated for not much.

But if you still want to find a answer, here is the problem:

I am making a search form by filter. In the header, there is all the textbox and combobox to enter the search criteria. There is so many of them, it's half the page.
So, I stacked them. I hided them and changed their height to 0. Because of the stacked layout, when one box height = 0, all the layout shrink. So, the header shrink too. The user can add boxes and the header grow and vice versa 10 000 times a day if he wants.

The problem is with Option buttons (Toggles). I don't know why, but they don't stack in the layout. So, I tried to move them manualy. But, I still don't know why, they wont move all toghether. I have to move them one by one (the little buttons). And I have 4 group of 4 buttons + 4 textboxes. So my header stay huge but seem empty (the are invisible).

And I can't filter with an subform.... :/
 

Attachments

  • ouvert.png
    ouvert.png
    30.5 KB · Views: 83
  • design.png
    design.png
    57.9 KB · Views: 86
  • ferme.png
    ferme.png
    26.8 KB · Views: 83

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:26
Joined
Feb 28, 2001
Messages
27,223
LeslyP - have you looked at using TABBED pages? Put the main form on one tab and the search controls on another tab. You can even trigger a search and then when done, programmatically switch tabs.

Ridders, it may be that over the years since Access v2, the interaction between "visible" and "enabled" has changed. But you used to need to attend to both properties.

It actually makes sense that making something invisible would also disable it. Given that we ARE dealing with a Microsoft product here, that's why I doubt that such a sensible treatment change has occurred. But then, I am rarely known to be somewhat cynical.
 

isladogs

MVP / VIP
Local time
Today, 05:26
Joined
Jan 14, 2017
Messages
18,246
Ridders, it may be that over the years since Access v2, the interaction between "visible" and "enabled" has changed. But you used to need to attend to both properties.

It actually makes sense that making something invisible would also disable it. Given that we ARE dealing with a Microsoft product here, that's why I doubt that such a sensible treatment change has occurred. But then, I am rarely known to be somewhat cynical.

I started using Access97 and am fairly sure the two properties weren't linked even then. Unable to check as I no longer have it.

Occasionally MS does make some sensible changes...not often though!
 

LeslyP

Registered User.
Local time
Yesterday, 21:26
Joined
Apr 27, 2018
Messages
34
LeslyP - have you looked at using TABBED pages? Put the main form on one tab and the search controls on another tab. You can even trigger a search and then when done, programmatically switch tabs.

I can't figure out how to do that. I'm using Allen Browne's code to filter my form. How can I put the searches controls on another tab ? I thought it had to be on the header ? Damn... the more I learn about Access, the more I see I know nothing !

Sorry, I might just be tired ^^"
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:26
Joined
Feb 28, 2001
Messages
27,223
The thing about tabbed pages is that they are still on the same form as stuff on other tabs. A tab is similar conceptually to a section in some ways, but EVERY CONTROL on the form is visible to code for ANY events on that form or under its controls, regardless of which tab actually "hosts" that control. So if you have your busy search controls on one tab and your results on another tab (and can make the tab switch for you), you just got double the form space.
 

Mark_

Longboard on the internet
Local time
Yesterday, 21:26
Joined
Sep 12, 2017
Messages
2,111
You would add a Tab control to your header. You would add a tab for each logical area you will be using. You would then move your controls to the individual tab that matches their logical area. You would then have Biomasse in several short colums on one tab, Parametres on another (or several other), ect.
 

LeslyP

Registered User.
Local time
Yesterday, 21:26
Joined
Apr 27, 2018
Messages
34
I will have to try later. For now, I have to move on Something else. But thank you very much for your help!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:26
Joined
Feb 19, 2002
Messages
43,352
I wouldn't put the tab control in the header. I would reduce the size of the header and just use the detail section of the form for the tab control.

To move the controls from where they are to a tab page, you will select them all and cut. Move focus to the tab page (it will highlight) and then paste. If you drag the controls, they will bleed through all the tabs rather than just showing on one tab page.
 

Users who are viewing this thread

Top Bottom