Reputation: 568
Is there any index to control which picture, textbox, frame... will be in front of the other? Is there any property similar tor the PHP's z-index?
I am trying to right click and sending backward, but I get no change.
Upvotes: 4
Views: 17347
Reputation: 1
Yes, you can programmatically move UserForm Controls either to the Front or Back by using "ZOrder
".
The syntax is:MyUserForm.MyControl.ZOrder (zPosition)
fmTop
or 0
sets it to the top, visible over everything else on the Userform:MyUserForm.MyControl.ZOrder (fmTop)
or MyUserForm.MyControl.ZOrder (0)
fmBottom
or 1
sets it to the bottom, hidden under everything else on the UserForm:MyUserForm.MyControl.ZOrder (fmBottom)
or MyUserForm.MyControl.ZOrder (1)
I'm not aware of any way to set a specific layer of visibility in between top and bottom (say, above Control "X", but below Control "Y") other than to loop through the respective UserFrom Controls, and place them one on top of the other, like building blocks, similar to that you can't put a block in the middle of an existing tower of blocks. You have to put the block where you want it, and then add the others, one at a time, above that placed block. (Of course, you can place either above or below in VBA, as gravity doesn't apply. ;)
Note that the fmTop
and fmBottom
preset variables function similarly to the vbYes
(6
) and vbNo
(7
) preset variables, but are named relative to UserForms (Forms: "fm
"), as opposed to the global VBA application (VBA: "vb
"). You can still use fmTop
as "0" and fmBottom
as "1" for anything in VBA, but "0" and "1" in a given index don't always refer to vertical placement within that index. Just sayin'. ;)
I don't know if this is a change or not (considering that this question was previously asked almost nine years ago), but there's the current solution.
Upvotes: 0
Reputation: 21
In response to this old question of moving items to the front or rear on Excel forms, I have found that the "Bring Forward" and "Send Backward" controls do not work. By accident I found that if you delete an item in an Excel form and then undelete it, it will move it to the front.
Upvotes: 2
Reputation: 2185
After a fair bit of searching, it would seem the answer to your question is No. There doesn't appear to be any way to adjust the Zorder or use "Bring to Front" or "Send to Back" in VBA. As per the answer here:
Use Z-order and position to organize open forms in MS Access
And here:
Microsoft Access z-index property
The only alternative I have found mentioned was to layer your controls perfectly and the use .Setfocus
to bring them to the front. Personally in my database I simply just toggle .Visible
for the control to False
or True
in order to give the illusion of controls "Moving".
Note: After reviewing your tags I notice you don't have an Excel or Access one in there. My answer is based off of Access, if you are using excel please adjust your tags.
Upvotes: 1