Locking position of Custom Toolbar

  • Thread starter Thread starter OssieMac
  • Start date Start date
O

OssieMac

I have a custom toolbar set to display when a form opens. How can I lock the
position of a custom toolbar so that it can't be moved and always displays in
the same place when the form opens.
 
Thanks Alex. You put me on the right track to overcome the problem. I
actually wrote some code in a module to return the required parameters and
then set the position of both the form and toolbar in the On Open event.
Since I couldn't find anything on it in the forum, I thought that it might
help someone else if I post the code I used.

The following code to get the parameters:-

Sub Form_And_ToolBar_Positions()
'Use this sub in a module to identify the position of
'the form and toolbar

Dim frmProduct As Form
Dim objTBar As Object

Set frmProduct = Forms![Product Details]

With frmProduct
MsgBox "Form Name: " & .Name & Chr(13) & _
"WindowLeft: " & .WindowLeft & Chr(13) & _
"WindowTop: " & .WindowTop & Chr(13) & _
"WindowHeight: " & .WindowHeight & Chr(13) & _
"WindowWidth: " & .WindowWidth
End With

Set objTBar = CommandBars("FilterData")

With objTBar
MsgBox "Tool Bar Name: " & .Name & Chr(13) & _
"Tool Bar Top: " & .Top & Chr(13) & _
"Tool Bar Left: " & .Left
End With

End Sub

The following code in the On Open event:-

Private Sub Form_Open(Cancel As Integer)
'On Open code for the form to position form and toolbar

Dim objTBar As Object

Me.Move Left:=2910, Top:=200, Width:=11085, Height:=8715

Set objTBar = CommandBars("FilterData")

With objTBar
.Top = 151
.Left = 606
End With

End Sub

One little glitch. The value for the top of the form may have to be adjusted
in the on open event because it appears to measure from the bottom of any
toolbars before they are closed due to the Forms Toolbar property instead of
measuring it after the toolbars are closed.


--
Regards,

OssieMac


Alex Dybenko said:
Hi,
don't know if you can really lock the position, but I would try to save
commadbar Left and Top properties on form close and then set it to saved
values on form open

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 
Thanks for code, OssieMac!

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com

OssieMac said:
Thanks Alex. You put me on the right track to overcome the problem. I
actually wrote some code in a module to return the required parameters and
then set the position of both the form and toolbar in the On Open event.
Since I couldn't find anything on it in the forum, I thought that it might
help someone else if I post the code I used.

The following code to get the parameters:-

Sub Form_And_ToolBar_Positions()
'Use this sub in a module to identify the position of
'the form and toolbar

Dim frmProduct As Form
Dim objTBar As Object

Set frmProduct = Forms![Product Details]

With frmProduct
MsgBox "Form Name: " & .Name & Chr(13) & _
"WindowLeft: " & .WindowLeft & Chr(13) & _
"WindowTop: " & .WindowTop & Chr(13) & _
"WindowHeight: " & .WindowHeight & Chr(13) & _
"WindowWidth: " & .WindowWidth
End With

Set objTBar = CommandBars("FilterData")

With objTBar
MsgBox "Tool Bar Name: " & .Name & Chr(13) & _
"Tool Bar Top: " & .Top & Chr(13) & _
"Tool Bar Left: " & .Left
End With

End Sub

The following code in the On Open event:-

Private Sub Form_Open(Cancel As Integer)
'On Open code for the form to position form and toolbar

Dim objTBar As Object

Me.Move Left:=2910, Top:=200, Width:=11085, Height:=8715

Set objTBar = CommandBars("FilterData")

With objTBar
.Top = 151
.Left = 606
End With

End Sub

One little glitch. The value for the top of the form may have to be
adjusted
in the on open event because it appears to measure from the bottom of any
toolbars before they are closed due to the Forms Toolbar property instead
of
measuring it after the toolbars are closed.
 
Back
Top