问题已开启 (普通问题)
Access2010如何在菜单栏中添加自定义的菜单和子菜单
怎么才能在菜单栏的加载项中添加你的菜单和子菜单呢,也就是ACCESS中的查询都在自定义的菜单栏中用下拉菜单显示出来呢?
下面这些命令都复制在模块中了,要用什么命令才能把菜单和子菜单自动载入到菜单中呢--如附件图?谢谢!

复制来的代码:

Option Compare Database
Sub 设置工具栏()
Dim newBar As CommandBar
Dim newButton As CommandBarButton
On Error Resume Next
Set newBar = Application.CommandBars.Add("xtgj", msoBarTop)
If Err.Number > 0 Then
Application.CommandBars("xtgj").Delete '删除
Set newBar = Application.CommandBars.Add("xtgj", msoBarTop)
End If
newBar.Visible = True
Set db = CurrentDb
sql1 = "SELECT  * FROM 工具栏  ORDER BY 序号 "
Set rs = db.OpenRecordset(sql1, 2, 512)
If Not rs.EOF Then rs.MoveFirst
While Not rs.EOF
If rs("类型") = "命令按钮" Then
  Set newButton = newBar.Controls.Add(msoControlButton, rs("ID"))
Else
  Set newButton = newBar.Controls.Add(msoControlComboBox, rs("ID"))
End If
If Not rs.EOF Then rs.MoveNext
Wend
rs.Close
Set db = Nothing
Set rs = Nothing
End Sub
Public Sub 动态菜单()
Const bm As String = "主菜单"
Const bm1 As String = "子菜单"
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rs1 As DAO.Recordset
Dim sql1 As String
Dim bar As CommandBar
Dim mybar As CommandBarControl
On Error Resume Next
Set bar = Application.CommandBars.Add("xtcd", msoBarTop, True, True)
If Err.Number > 0 Then
Application.CommandBars("xtcd").Delete
Set bar = Application.CommandBars.Add("xtcd", msoBarTop, True, True)
rr.Number = 0
End If
With bar
.Protection = msoBarNoMove
.Visible = True
End With
Set db = CurrentDb
sql1 = "SELECT  * FROM " & bm & " ORDER BY ID DESC"
Set rs = db.OpenRecordset(sql1)
If Not rs.EOF Then rs.MoveFirst
While Not rs.EOF
Set mybar = bar.Controls.Add(Type:=msoControlPopup, Before:=1)
With mybar
.Caption = rs("主菜单")
End With
sql1 = "SELECT  * FROM " & bm1 & " where ID=" & rs("ID") & " ORDER BY ZID DESC"
Set rs1 = db.OpenRecordset(sql1)
If Not rs1.EOF Then rs1.MoveFirst
While Not rs1.EOF
  Set mybar1 = mybar.Controls.Add(Type:=msoControlButton, Before:=1)
  With mybar1
   .Caption = rs1("子菜单")
   .Visible = True
   .OnAction = "菜单接口"   '将激活的过程名称
   .Tag = rs1("ZID")
  End With
  If Not rs1.EOF Then rs1.MoveNext
Wend
rs1.Close
If Not rs.EOF Then rs.MoveNext
Wend
rs.Close
Set db = Nothing
Set rs = Nothing
Set rs1 = Nothing
End Sub
Sub 菜单接口()
Const bm1 As String = "子菜单"
Dim db As DAO.Database
Dim rs As DAO.Recordset
On Error GoTo err1  '如果有错误,转错误处理
Set db = CurrentDb
sql1 = "SELECT  * FROM " & bm1 & " where ZID=" & CommandBars.ActionControl.Tag
Set rs = db.OpenRecordset(sql1)
Select Case rs("打开类别")  '根据所选的“打开类别”进行相应的操作
Case 1  '类别为窗体
DoCmd.OpenForm rs("名称"), rs("视图类型")  '根据视图类型打开窗体
Case 2  '类别为查询
If rs("视图类型") > 2 Then  ''视图类型不符合要求时,自动按打印预览视图处理
  DoCmd.OpenQuery rs("名称"), 2
Else
  DoCmd.OpenQuery rs("名称"), rs("视图类型")  '根据视图类型打开查询
End If
Case 3  '类别为报表
If rs("视图类型") > 2 And rs("视图类型") < 5 Then  '视图类型不符合要求时,自动按打印预览视图处理
  DoCmd.OpenReport rs("名称"), 2
Else
  DoCmd.OpenReport rs("名称"), rs("视图类型") '根据视图类型打开报表
End If
Case 4  '类别为表
DoCmd.OpenTable rs("名称"), rs("视图类型"), acReadOnly  '根据视图类型以只读方式打开表
Case 5  '类别为代码
DoCmd.RunMacro rs("名称")
Case 6  '类别为话统
dsp_result (rs("名称"))
Case 7
Call input_sta
Case 8  '类别为代码
Call 动态菜单
Case Else  '错误的打开类别处理
MsgBox ("打开类别输入错误")
  
End Select
Exit Sub  '退出
err1:  '错误处理
MsgBox ("还没有定义这个功能," & "不能打开这个“" & rs("名称") & "”")
End Sub
Sub 删除菜单()
On Error GoTo err1
Application.CommandBars("xtcd").Delete
err1:
End Sub
Sub 菜单有效设置(gn) '所带参数(gn=(1--菜单有效,其他--无效))
On Error GoTo err1
If gn = 1 Then
Application.CommandBars("xtcd").Enabled = True '有效
Else
Application.CommandBars("xtcd").Enabled = False '无效
End If
err1:
End Sub
Sub 菜单可见设置(gn) '所带参数(gn=(1--菜单可见,其他--不可见))
On Error GoTo err1
If gn = 1 Then
Application.CommandBars("xtcd").Visible = True '可见
Else
Application.CommandBars("xtcd").Visible = False '不可见
End If
err1:
End Sub
Sub 主菜单有效设置(zxh, gn) '所带参数(zxh=主菜单序号,gn=(1--菜单有效,其他--无效))
Dim js
On Error GoTo err1
js = Application.CommandBars("xtcd").Controls.Count
If zxh > js And zxh < js Then
MsgBox ("参数错误,主菜单序号不能大于或小于主菜单表中的记录数")
Exit Sub
End If
If gn = 1 Then
Application.CommandBars("xtcd").Controls(zxh).Enabled = True '有效
Else
Application.CommandBars("xtcd").Controls(zxh).Enabled = False '无效
End If
err1:
End Sub
Sub 主菜单可见设置(zxh, gn) '所带参数(zxh=主菜单序号,gn=(1--菜单可见,其他--隐藏))
Dim js
On Error GoTo err1
js = Application.CommandBars("xtcd").Controls.Count
If zxh > js And zxh < js Then
MsgBox ("参数错误,主菜单序号不能大于或小于主菜单表中的记录数")
Exit Sub
End If
If gn = 1 Then
Application.CommandBars("xtcd").Controls(zxh).Visible = True  '可见
Else
Application.CommandBars("xtcd").Controls(zxh).Visible = False '隐藏
End If
err1:
End Sub
Sub 子菜单有效设置(zxh, gn) '所带参数(zxh=主菜单序号,gn=(1--菜单有效,其他--无效))
Dim i As Integer
Dim js
On Error GoTo err1
js = Application.CommandBars("xtcd").Controls.Count
If zxh > js And zxh < js Then
MsgBox ("参数错误,主菜单序号不能大于或小于主菜单表中的记录数")
Exit Sub
End If
For i = 1 To Application.CommandBars("xtcd").Controls(zxh).Controls.Count
If gn = 1 Then
  Application.CommandBars("xtcd").Controls(zxh).CommandBar.Controls(i).Enabled = True '有效
Else
  Application.CommandBars("xtcd").Controls(zxh).CommandBar.Controls(i).Enabled = False '无效
End If
Next i
err1:
End Sub
Sub 子菜单可见设置(zxh, gn) '所带参数(zxh=主菜单序号,gn=(1--菜单有效,其他--无效))
Dim i As Integer
Dim js
On Error GoTo err1
js = Application.CommandBars("xtcd").Controls.Count
If zxh > js And zxh < js Then
MsgBox ("参数错误,主菜单序号不能大于或小于主菜单表中的记录数")
Exit Sub
End If
For i = 1 To Application.CommandBars("xtcd").Controls(zxh).Controls.Count
If gn = 1 Then
  Application.CommandBars("xtcd").Controls(zxh).CommandBar.Controls(i).Visible = True '可见
Else
  Application.CommandBars("xtcd").Controls(zxh).CommandBar.Controls(i).Visible = False '隐藏
End If
Next i
err1:
End Sub
Sub 单个子菜单有效设置(zxh, z_xh, gn) '所带参数(zxh=主菜单序号,z_xh=子菜单序号,gn=(1--菜单有效,其他--无效))
Dim js
On Error GoTo err1
js = Application.CommandBars("xtcd").Controls.Count
If zxh > js And zxh < js Then
MsgBox ("参数错误,主菜单序号不能大于或小于主菜单表中的记录数")
Exit Sub
End If
js = Application.CommandBars("xtcd").Controls(zxh).Controls.Count
If zxh > js And zxh < js Then
MsgBox ("参数错误,子菜单序号不能大于或小于该主菜单下的子菜单")
Exit Sub
End If
If gn = 1 Then
Application.CommandBars("xtcd").Controls(zxh).CommandBar.Controls(z_xh).Enabled = True '有效
Else
Application.CommandBars("xtcd").Controls(zxh).CommandBar.Controls(z_xh).Enabled = False '无效
End If
err1:
End Sub

Sub 单子菜单可见设置(zxh, z_xh, gn) '所带参数(zxh=主菜单序号,z_xh=子菜单序号,gn=(1--菜单可见,其他--隐藏))
Dim js
On Error GoTo err1
js = Application.CommandBars("xtcd").Controls.Count
If zxh > js And zxh < js Then
MsgBox ("参数错误,主菜单序号不能大于或小于主菜单表中的记录数")
Exit Sub
End If
js = Application.CommandBars("xtcd").Controls(zxh).Controls.Count
If zxh > js And zxh < js Then
MsgBox ("参数错误,子菜单序号不能大于或小于该主菜单下的子菜单")
Exit Sub
End If
If gn = 1 Then
Application.CommandBars("xtcd").Controls(zxh).CommandBar.Controls(z_xh).Visible = True '可见
Else
Application.CommandBars("xtcd").Controls(zxh).CommandBar.Controls(z_xh).Visible = False '隐藏
End If
err1:
End Sub


提问者: beichen  提问时间: 2013-01-22    
 
  我要回答:
 

  请先 登录注册 再回答问题

更多 CCE ACC CES ESS access E_S 201 相关问题
问题答案 ( 0 )
中国通信人才网 | 江苏通信人才网 | 山东通信人才网 | 武汉通信人才网 | 浙江通信人才网 | 湖南通信人才网
上海睿铎智能科技有限公司 聘:江苏盐城700M外场
需求人数:1 人 地点:盐城市
中移铁通有限公司江门分公司 聘:高铁专网维护员
需求人数:2 人 地点:江门市
南京华苏科技有限公司 聘:高级优化人员
需求人数:3 人 地点:福州市
重庆信科通信工程有限公司 聘:四川巴中-IMC招聘
需求人数:1 人 地点:巴中市
嘉环科技股份有限公司 聘:测试工程师
需求人数:15 人 地点:昆明市,临沧市,德宏州,红河州,玉溪市
广州楚晨网络科技有限公司 聘:4G/5G后台中高级工程师
需求人数:12 人 地点:广东省
杭州东信网络技术有限公司 聘:长期-廊坊-5G华为后台
需求人数:1 人 地点:廊坊市
上海瑞禾通讯技术有限公司 聘:广州中高级工程师
需求人数:3 人 地点:广州市
北京电旗通讯技术股份有限公司 聘:网优实习生通信应届生(云南)
需求人数:1 人 地点:昆明市,思茅市,昭通市
成都旗讯通信技术有限公司 聘:5月6日金牌网优后台实训新班开课
需求人数:12 人 地点:北京市,上海市,天津市,重庆市,四川省
热点问题
更多精彩

联系我们 - 问通信专家 Powered by MSCBSC 移动通信网  © 2006 -