设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

[原创]自动为窗体和报表添加代码并设置右键菜单

2008-6-12 20:37| 发布者: 5988143| 查看: 2110| 评论: 3

'自动为窗体和报表添加代码并设置右键菜--tmtony 2003/10/23
'如果你需要为很多窗体或报表重复添加一些代码, 或者需要设置是否允许显示右键菜单,显示什么菜单等,可使用下面的函数来自动编写代码,举一反三, 使用这种方法可实现很多丰富的功能

Public Function gfuncTransFrmAndRpt()
Dim ctr As Control
Dim strInfo(30, 7) As String
Dim iCnt As Integer
Dim i As Integer
Dim rpt As Report
dim frm as Form
Dim mdl As Module
Dim lngCount As Long, lngEndProc As Long, lngBodyLine As Long, lngStartLine As Long
Dim strProcName As String
Dim strNote As String
On Error Resume Next
Set rpt = Screen.ActiveReport
'If InStr(rpt.Tag, "..") > 0 Then Exit Function
Dim aoj As AccessObject
'设置所有窗体的右键菜单(或禁用),并自动添加初始化代码到窗体的打开事件中
For Each aoj In CurrentProject.AllForms
DoCmd.OpenForm aoj.Name, acDesign,,,,acHidden
Set frm = Forms(aoj.Name)

frm.ShortcutMenu =False
'frm.ShortcutMenu =True '如果要设置有右键菜单,请使用这两句
'frm.ShortcutMenuBar = "erpRpt"
Set mdl = rpt.Module
lngCount = 0
strProcName = "Form_Open"
lngCount = mdl.ProcCountLines(strProcName, vbext_pk_Proc)
If lngCount > 0 Then Err.Number = 0
If Err.Number <> 0 Then lngCount = 0
If lngCount = 0 Then
mdl.CreateEventProc "Open", "Form"
End If
lngCount = mdl.ProcCountLines(strProcName, vbext_pk_Proc)
lngStartLine = mdl.ProcStartLine(strProcName, vbext_pk_Proc)
lngBodyLine = mdl.ProcBodyLine(strProcName, vbext_pk_Proc)
lngEndProc = (lngBodyLine + lngCount - 1) - Abs(lngBodyLine - lngStartLine)
If Not mdl.Find("glInitRptStyle Me", 0, 0, mdl.CountOfLines, 300) Then
mdl.InsertLines lngBodyLine + 1, vbTab & "glInitFrmStyle Me '调用通用窗体初始化过程 "
End If
DoCmd.Close acForm, aoj.Name, acSaveYes
Next


'设置所有报表的右键菜单(或禁用),并自动添加初始化代码到报表的打开事件中
For Each aoj In CurrentProject.AllReports
DoCmd.OpenReport aoj.Name, acViewDesign
Set rpt = Reports(aoj.Name)
rpt.ShortcutMenuBar = "erpRpt"
Set mdl = rpt.Module
lngCount = 0
strProcName = "Report_Open"
lngCount = mdl.ProcCountLines(strProcName, vbext_pk_Proc)
If lngCount > 0 Then Err.Number = 0
If Err.Number <> 0 Then lngCount = 0
If lngCount = 0 Then
mdl.CreateEventProc "Open", "Report"
End If
lngCount = mdl.ProcCountLines(strProcName, vbext_pk_Proc)
lngStartLine = mdl.ProcStartLine(strProcName, vbext_pk_Proc)
lngBodyLine = mdl.ProcBodyLine(strProcName, vbext_pk_Proc)
lngEndProc = (lngBodyLine + lngCount - 1) - Abs(lngBodyLine - lngStartLine)
If Not mdl.Find("glInitRptStyle Me", 0, 0, mdl.CountOfLines, 300) Then
mdl.InsertLines lngBodyLine + 1, vbTab & "glInitRptStyle Me '调用通用报表初始化过程 "
End If
DoCmd.Close acReport, aoj.Name, acSaveYes
Next


End Function

发表评论

最新评论

引用 xie62 2010-5-5 09:40
不错
引用 panguang 2008-11-25 21:17
不懂
引用 oubing 2008-6-13 06:06
我不懂怎么办

查看全部评论(3)

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-29 21:01 , Processed in 0.090054 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部