問題已開啟 (普通問題)
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 動態(tài)菜單()
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("打開類別")  '根據(jù)所選的“打開類別”進行相應的操作
Case 1  '類別為窗體
DoCmd.OpenForm rs("名稱"), rs("視圖類型")  '根據(jù)視圖類型打開窗體
Case 2  '類別為查詢
If rs("視圖類型") > 2 Then  ''視圖類型不符合要求時,自動按打印預覽視圖處理
  DoCmd.OpenQuery rs("名稱"), 2
Else
  DoCmd.OpenQuery rs("名稱"), rs("視圖類型")  '根據(jù)視圖類型打開查詢
End If
Case 3  '類別為報表
If rs("視圖類型") > 2 And rs("視圖類型") < 5 Then  '視圖類型不符合要求時,自動按打印預覽視圖處理
  DoCmd.OpenReport rs("名稱"), 2
Else
  DoCmd.OpenReport rs("名稱"), rs("視圖類型") '根據(jù)視圖類型打開報表
End If
Case 4  '類別為表
DoCmd.OpenTable rs("名稱"), rs("視圖類型"), acReadOnly  '根據(jù)視圖類型以只讀方式打開表
Case 5  '類別為代碼
DoCmd.RunMacro rs("名稱")
Case 6  '類別為話統(tǒng)
dsp_result (rs("名稱"))
Case 7
Call input_sta
Case 8  '類別為代碼
Call 動態(tài)菜單
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) '所帶參數(shù)(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) '所帶參數(shù)(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) '所帶參數(shù)(zxh=主菜單序號,gn=(1--菜單有效,其他--無效))
Dim js
On Error GoTo err1
js = Application.CommandBars("xtcd").Controls.Count
If zxh > js And zxh < js Then
MsgBox ("參數(shù)錯誤,主菜單序號不能大于或小于主菜單表中的記錄數(shù)")
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) '所帶參數(shù)(zxh=主菜單序號,gn=(1--菜單可見,其他--隱藏))
Dim js
On Error GoTo err1
js = Application.CommandBars("xtcd").Controls.Count
If zxh > js And zxh < js Then
MsgBox ("參數(shù)錯誤,主菜單序號不能大于或小于主菜單表中的記錄數(shù)")
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) '所帶參數(shù)(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 ("參數(shù)錯誤,主菜單序號不能大于或小于主菜單表中的記錄數(shù)")
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) '所帶參數(shù)(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 ("參數(shù)錯誤,主菜單序號不能大于或小于主菜單表中的記錄數(shù)")
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) '所帶參數(shù)(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 ("參數(shù)錯誤,主菜單序號不能大于或小于主菜單表中的記錄數(shù)")
Exit Sub
End If
js = Application.CommandBars("xtcd").Controls(zxh).Controls.Count
If zxh > js And zxh < js Then
MsgBox ("參數(shù)錯誤,子菜單序號不能大于或小于該主菜單下的子菜單")
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) '所帶參數(shù)(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 ("參數(shù)錯誤,主菜單序號不能大于或小于主菜單表中的記錄數(shù)")
Exit Sub
End If
js = Application.CommandBars("xtcd").Controls(zxh).Controls.Count
If zxh > js And zxh < js Then
MsgBox ("參數(shù)錯誤,子菜單序號不能大于或小于該主菜單下的子菜單")
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 )
中國通信人才網(wǎng) | 江蘇通信人才網(wǎng) | 山東通信人才網(wǎng) | 武漢通信人才網(wǎng) | 浙江通信人才網(wǎng) | 湖南通信人才網(wǎng)
重慶信科通信工程有限公司 聘:南昌電信中興原廠高級
需求人數(shù):2 人 地點:南昌市
浙江明訊網(wǎng)絡技術有限公司 聘:浙江網(wǎng)絡優(yōu)化工程師
需求人數(shù):8 人 地點:寧波市,舟山市,湖州市,紹興市
北京宜通華瑞科技有限公司 聘:電信原廠優(yōu)化中高級(江西急聘)
需求人數(shù):5 人 地點:景德鎮(zhèn)市,南昌市
杭州東信網(wǎng)絡技術有限公司 聘:LTE/5G網(wǎng)絡中高級優(yōu)化工程師
需求人數(shù):2 人 地點:上海市
廈門特力通通信工程有限公司 聘:移動4/5G網(wǎng)絡投訴工單處理
需求人數(shù):1 人 地點:莆田市
安徽引途科技有限公司 聘:皖北地區(qū)單驗測試工程師
需求人數(shù):20 人 地點:安徽省
廣東南方通信建設有限公司 聘:日常項目系統(tǒng)中高級工程師
需求人數(shù):2 人 地點:百色市
南京華蘇科技有限公司 聘:投訴處理(后臺)-?
需求人數(shù):2 人 地點:海口市
元道通信股份有限公司 聘:初級前臺測試/福建
需求人數(shù):3 人 地點:泉州市,三明市,南平市
杭州華星創(chuàng)業(yè)通信技術股份有限公司 聘:督導開站-初中級后臺-山東
需求人數(shù):20 人 地點:山東省
熱點問題
更多精彩

聯(lián)系我們 - 問通信專家 Powered by MSCBSC 移動通信網(wǎng)  © 2006 -