2013-03-21 85 views
1

有没有办法对Access 2010导航表格上的导航按钮进行动态重新排序?VBA - 重新访问Access 2010导航表格选项卡索引

我想根据用户类型隐藏某些按钮;但如果订单无法修改,只需隐藏它们就会在按钮之间留下间隙。

我试过类似于以下,没有运气。

Me.NavigationButton1.TabIndex = 1 
Me.NavigationButton2.TabIndex = 0 

Me.Requery 
Me.Refresh 

在此先感谢您。

回答

1

NavigationButtons的工作方式有点不同。他们在NavigationControl容器中进行管理,如果底层按钮被隐藏,容器不会自动调整大小。通过使用该控件的Tag财产作为临时存储

' Always remember the normal size of the button ' 
Static bt1Witdh as Long 
if bt1Width = 0 then bt1Width = Me.NavigationButton1.Width 

' Now hide the button ' 
Me.NavigationButton1.Width = 0 
Me.NavigationButton1.Visible = False 

' Unhide the button ' 
Me.NavigationButton1.Visible = true 
Me.NavigationButton1.Width = bt1Width 

可以使这个有很多更通用的,有点“哈克”:

但是,你可以试试这个,它为我工作保持其正常宽度的轨道:

Public Sub HideNavigationButton(bt As NavigationButton) 
    ' Store the width if we haven't already done so ' 
    If bt.Tag = vbNullString Then bt.Tag = CStr(bt.Width) 

    bt.Width = 0 
    bt.Visible = False 
End Sub 

Public Sub ShowNavigationButton(bt As NavigationButton) 
    If bt.Visible Or bt.Width > 0 Then Exit Sub 

    bt.Visible = True 
    bt.Width = CInt(bt.Tag) 
End Sub 

要使用它:

' Hide ' 
HideNavigationButton Me.NavigationButton1 

' Show ' 
ShowNavigationButton Me.NavigationButton1