更新3/15/19以在“一般声明”部分中添加新的声明代码:
Option Compare Database
' Access global variables definition
Global bInReportOpenEvent As Boolean
Option Explicit
我收到错误:
“作为事件属性设置输入的On Open表达式产生了以下错误:常量,固定长度字符串,数组,用户定义类型和Declare语句不允许作为对象模块的Pubblic成员。”
更新3/15/19以添加声明代码。仍然在调用Dialog表单时丢失了bInReportOpenEvent值。
Option Compare Database
Dim bInReportOpenEvent As Boolean
Function IsLoaded(strNme As String) As Boolean
IsLoaded = CurrentProject.AllForms(strNme).IsLoaded
End Function
我正在创建一个访问报告,该报告调用对话框表单以提示在报告中显示特定记录。该报告使用查询作为记录源。我在“报告打开”模块中设置了一个全局字段,因此无法单独执行“对话框表单”。如果调用了对话框表单并且未设置由报告设置的全局字段,那么我想退出并显示一条消息。我的报告打开模块如下所示:
Public Sub Report_Open(Cancel As Integer)
Dim outCome1 As String
' Set public variable to true to indicate that the report
' is in the Open event
bInReportOpenEvent = True
MsgBox (bInReportOpenEvent)
' Open Appt Query Dialog
DoCmd.OpenForm "craid CMM Client Report Dialog", , , , , acDialog
' Cancel Report if User Clicked the Cancel Button
If IsLoaded("craid CMM Client Report Dialog") = False Then Cancel = True
MsgBox ("Is Dialog Form Loaded?")
MsgBox (IsLoaded("craid CMM Client Report Dialog"))
'outCome1 = (Reports("CMM Client Status Report").Controls("googleoutcome").Value)
'MsgBox (outCome1)
' Set public variable to false to indicate that the
' Open event is completed
bInReportOpenEvent = False
End Sub
我的对话表格表格打开如下:
Private Sub Form_Open(Cancel As Integer)
If Not bInReportOpenEvent Then
MsgBox ("In Not bInReportOpenEvent Logic")
MsgBox (bInReportOpenEvent)
' If we're not called from the report
MsgBox "For Use From CMM Client Status Report Only", _
vbOKOnly
Cancel = True
End If
End Sub
有什么想法吗?任何帮助赞赏。
我的问题得到了回答。解决方案是在VBA代码模块中声明全局变量。