Bring to front in VBA

M

Marshall Barton

MarioH said:
I want to bring all command buttons to front in VBA code because tooltips do
not display if the control is not "in front".

http://support.microsoft.com/default.aspx?scid=kb;en-us;232191

DoCmd.RunCommand acCmdBringToFront only works if I step through code and
then select the desired control manually.

Is there a way to select a control in VBA code in a form open in design view?


Since that can not be done at runtime, I must assume that
you are using code just to make it easier for you to work in
design view. If that's the case, I will argue that it is
far easier to just select the specifc controls manally and
use the Format menu item, Bring to Front. You can select
multiple controls by holding down the Shift key as you click
on individual controls or drag a selection rectangle around
multiple controls.

If you really are hoping to do this at runtime, you'll
either have to give up on the idea or set the focus to the
appropriate control, which automatically displays it in
front of other controls.
 
G

Guest

Marshall Barton said:
Since that can not be done at runtime, I must assume that
you are using code just to make it easier for you to work in
design view. If that's the case, I will argue that it is
far easier to just select the specifc controls manally and
use the Format menu item, Bring to Front. You can select
multiple controls by holding down the Shift key as you click
on individual controls or drag a selection rectangle around
multiple controls.

If you really are hoping to do this at runtime, you'll
either have to give up on the idea or set the focus to the
appropriate control, which automatically displays it in
front of other controls.
Thanks for your reply.
I have nearly 500 Forms with thousands of buttons that I want to bring to
front so tooltips display correctly. I want to cycle trough all forms and
bring the all command buttons to front in VBA. Doing this manually will be a
VERY tedious task !!! Are you sure that there is no way to do this in code?

Code sample:look at comment: How can I make this work
Sub ResetFormsAnd Reports()
' Run this procedure once to reset all
' the sorting and filtering options on all
' your forms and reports.
Dim frm As Form
Dim rpt As Report
Dim obj As AccessObject
Dim ctl As Control

' Loop through all the forms:
For Each obj In CurrentProject.AllForms
DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
Set frm = Forms(obj.Name)
frm.Filter = ""
frm.FilterOn = False
frm.OrderBy = ""
frm.OrderByOn = False
If frm.AllowDesignChanges = True Then
frm.AllowDesignChanges = False
End If
If frm.ViewsAllowed = 0 Then
frm.ViewsAllowed = 1
End If
For Each ctl In Forms(obj.Name).Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox
.AllowAutoCorrect = False
'How can I make this work
Case acCommandButton
DoCmd.RunCommand acCmdBringToFront
End Select
End With
Next ctl
DoCmd.Close acForm, obj.Name, acSaveYes
Next obj

' Loop through all the reports:
For Each obj In CurrentProject.AllReports
DoCmd.OpenReport obj.Name, acDesign
Set rpt = Reports(obj.Name)
rpt.Filter = ""
rpt.FilterOn = False
rpt.OrderBy = ""
rpt.OrderByOn = False
DoCmd.Close acReport, obj.Name, acSaveYes
Next obj
End Sub
 
M

Marshall Barton

MarioH said:
I have nearly 500 Forms with thousands of buttons that I want to bring to
front so tooltips display correctly. I want to cycle trough all forms and
bring the all command buttons to front in VBA. Doing this manually will be a
VERY tedious task !!! Are you sure that there is no way to do this in code?

Code sample:look at comment: How can I make this work
Sub ResetFormsAnd Reports()
' Run this procedure once to reset all
' the sorting and filtering options on all
' your forms and reports.
Dim frm As Form
Dim rpt As Report
Dim obj As AccessObject
Dim ctl As Control

' Loop through all the forms:
For Each obj In CurrentProject.AllForms
DoCmd.OpenForm obj.Name, acDesign, , , , acHidden [snip]
For Each ctl In Forms(obj.Name).Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox
.AllowAutoCorrect = False
'How can I make this work
Case acCommandButton
DoCmd.RunCommand acCmdBringToFront
End Select
[snip]


Ah yes, an excellent use of VBA to modify objects. Sorry
about the lecture, but it's very unusual to see anyone using
this kind of code for the right thing.

What you're looking for here is the InSelection property.

Case acCommandButton
.InSelection = True
DoCmd.RunCommand acCmdBringToFront

BUT, there's always one those bleeping buts, isn't there ;-)
The InSelection property will not reset to false
automatically, except when the form is closed.

I suggest that you use:
.InSelection = False
at the top of the loop to make sure you don't inadvertantly
mess up the Z-order of other controls. In the command
button case, just set InSelection to True and wait until
after the loop to bring all of them to the front in one
shot.
 
G

Guest

Marshall Barton said:
MarioH said:
I have nearly 500 Forms with thousands of buttons that I want to bring to
front so tooltips display correctly. I want to cycle trough all forms and
bring the all command buttons to front in VBA. Doing this manually will be a
VERY tedious task !!! Are you sure that there is no way to do this in code?

Code sample:look at comment: How can I make this work
Sub ResetFormsAnd Reports()
' Run this procedure once to reset all
' the sorting and filtering options on all
' your forms and reports.
Dim frm As Form
Dim rpt As Report
Dim obj As AccessObject
Dim ctl As Control

' Loop through all the forms:
For Each obj In CurrentProject.AllForms
DoCmd.OpenForm obj.Name, acDesign, , , , acHidden [snip]
For Each ctl In Forms(obj.Name).Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox
.AllowAutoCorrect = False
'How can I make this work
Case acCommandButton
DoCmd.RunCommand acCmdBringToFront
End Select
[snip]


Ah yes, an excellent use of VBA to modify objects. Sorry
about the lecture, but it's very unusual to see anyone using
this kind of code for the right thing.

What you're looking for here is the InSelection property.

Case acCommandButton
.InSelection = True
DoCmd.RunCommand acCmdBringToFront

BUT, there's always one those bleeping buts, isn't there ;-)
The InSelection property will not reset to false
automatically, except when the form is closed.

I suggest that you use:
.InSelection = False
at the top of the loop to make sure you don't inadvertantly
mess up the Z-order of other controls. In the command
button case, just set InSelection to True and wait until
after the loop to bring all of them to the front in one
shot.

I did reply to this post on 6/3/2005 but somehow it never appeared on the
forum???

So thank you very much again. You made my day.
I kicked myself for not having found this by looking in the object browser.
Why is this property (and others) not listed on the right mouse click
properties list?
Please note that the forms must be open in visible mode for this code to
work. (Not acHidden).
 
M

Marshall Barton

MarioH said:
I have nearly 500 Forms with thousands of buttons that I want to bring to
front so tooltips display correctly. I want to cycle trough all forms and
bring the all command buttons to front in VBA. Doing this manually will be a
VERY tedious task !!! Are you sure that there is no way to do this in code?

Code sample:look at comment: How can I make this work
Sub ResetFormsAnd Reports()
' Run this procedure once to reset all
' the sorting and filtering options on all
' your forms and reports.
Dim frm As Form
Dim rpt As Report
Dim obj As AccessObject
Dim ctl As Control

' Loop through all the forms:
For Each obj In CurrentProject.AllForms
DoCmd.OpenForm obj.Name, acDesign, , , , acHidden [snip]
For Each ctl In Forms(obj.Name).Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox
.AllowAutoCorrect = False
'How can I make this work
Case acCommandButton
DoCmd.RunCommand acCmdBringToFront
End Select
[snip]
Marshall Barton said:
Ah yes, an excellent use of VBA to modify objects. Sorry
about the lecture, but it's very unusual to see anyone using
this kind of code for the right thing.

What you're looking for here is the InSelection property.

Case acCommandButton
.InSelection = True
DoCmd.RunCommand acCmdBringToFront

BUT, there's always one those bleeping buts, isn't there ;-)
The InSelection property will not reset to false
automatically, except when the form is closed.

I suggest that you use:
.InSelection = False
at the top of the loop to make sure you don't inadvertantly
mess up the Z-order of other controls. In the command
button case, just set InSelection to True and wait until
after the loop to bring all of them to the front in one
shot.
MarioH said:
I did reply to this post on 6/3/2005 but somehow it never appeared on the
forum???
So thank you very much again. You made my day.
I kicked myself for not having found this by looking in the object browser.
Why is this property (and others) not listed on the right mouse click
properties list?
Please note that the forms must be open in visible mode for this code to
work. (Not acHidden).


Even though I was wondering if you got it to work, don't
worry about a lost message. A little while back, I had one
pop up on my(!?) screen two weeks after I had sent it???

The InSelection property, among others, can only be set
using VBA, so it makes sense for it not to be on the
Properties Sheet.

Yes, the form must be visible. AFAIK, an invisible object
can not (no good reason AFAICS) be selected by any means,
just like an invisible object can not receive the focus.

Glad you got all this sorted out, I'd hate to think about
making all those changes manually.
 
G

Guest

Marshall Barton said:
MarioH wrote:
I have nearly 500 Forms with thousands of buttons that I want to bring to
front so tooltips display correctly. I want to cycle trough all forms and
bring the all command buttons to front in VBA. Doing this manually will be a
VERY tedious task !!! Are you sure that there is no way to do this in code?

Code sample:look at comment: How can I make this work
Sub ResetFormsAnd Reports()
' Run this procedure once to reset all
' the sorting and filtering options on all
' your forms and reports.
Dim frm As Form
Dim rpt As Report
Dim obj As AccessObject
Dim ctl As Control

' Loop through all the forms:
For Each obj In CurrentProject.AllForms
DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
[snip]
For Each ctl In Forms(obj.Name).Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox
.AllowAutoCorrect = False
'How can I make this work
Case acCommandButton
DoCmd.RunCommand acCmdBringToFront
End Select
[snip]
Marshall Barton said:
Ah yes, an excellent use of VBA to modify objects. Sorry
about the lecture, but it's very unusual to see anyone using
this kind of code for the right thing.

What you're looking for here is the InSelection property.

Case acCommandButton
.InSelection = True
DoCmd.RunCommand acCmdBringToFront

BUT, there's always one those bleeping buts, isn't there ;-)
The InSelection property will not reset to false
automatically, except when the form is closed.

I suggest that you use:
.InSelection = False
at the top of the loop to make sure you don't inadvertantly
mess up the Z-order of other controls. In the command
button case, just set InSelection to True and wait until
after the loop to bring all of them to the front in one
shot.
MarioH said:
I did reply to this post on 6/3/2005 but somehow it never appeared on the
forum???
So thank you very much again. You made my day.
I kicked myself for not having found this by looking in the object browser.
Why is this property (and others) not listed on the right mouse click
properties list?
Please note that the forms must be open in visible mode for this code to
work. (Not acHidden).


Even though I was wondering if you got it to work, don't
worry about a lost message. A little while back, I had one
pop up on my(!?) screen two weeks after I had sent it???

The InSelection property, among others, can only be set
using VBA, so it makes sense for it not to be on the
Properties Sheet.

Yes, the form must be visible. AFAIK, an invisible object
can not (no good reason AFAICS) be selected by any means,
just like an invisible object can not receive the focus.

Glad you got all this sorted out, I'd hate to think about
making all those changes manually.

Id nid not mean the properties window but the Properties/Methods list
displayed with RIGHT MOUSE CLICK in the code window. (Intellisense?) Do you
know why some properties/methods (like InSelection) are missing from this
list?
 
M

Marshall Barton

MarioH said:
Id nid not mean the properties window but the Properties/Methods list
displayed with RIGHT MOUSE CLICK in the code window. (Intellisense?) Do you
know why some properties/methods (like InSelection) are missing from this
list?


That's an easy one to answer - the MS programmers missed it.

Actually, they missed quite a few of them, not only in the
Intellisense list, but there are some that are missing in
the Property Sheet (e.g. Page control doesn't show its
Visible property). Chalk it up to "no one's perfect", not
programmers, not testers, not even Help writers ;-)
Just remember to double check the Object Browser for things
you can't find in the usual places.
 
G

Guest

Marshall Barton said:
That's an easy one to answer - the MS programmers missed it.

Actually, they missed quite a few of them, not only in the
Intellisense list, but there are some that are missing in
the Property Sheet (e.g. Page control doesn't show its
Visible property). Chalk it up to "no one's perfect", not
programmers, not testers, not even Help writers ;-)
Just remember to double check the Object Browser for things
you can't find in the usual places.

Well, that's MS... Nobody is perfect but MS is incoherent to put it mildly.
After 11 years of Access I will now definitively remember to only trust the
Object Browser!?!?

Thanks again,

Mario
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Nested Tab Controls - Bring to Front 9
Bring to front 5
Bring to front 3
Bring to front 3
Bring To Front 5
Bring to front 1
Bring to front in vba 1
Why does not bring to front on a control work 0

Top