我有一个数据库,当它打开代码运行时,除了表单之外,它隐藏了 Access 中的所有内容。
这对用户来说看起来很棒,但我相信这会阻止我在 acViewPreview 视图中显示报告。
如果我阻止 On Load 代码运行,那么我可以在 acViewPreview 视图中查看报告。
我不完全理解隐藏 On Load 事件表单上所有内容的代码(我几年前复制了它并且它有效,但我不记得从哪里开始,所以不能相信实际的创建者)。
隐藏访问的代码:
Private Sub Form_Load()
Call fSetAccessWindow(0)
End Sub
Option Compare Database
Option Explicit
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3
Private Declare Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Function fSetAccessWindow(nCmdShow As Long)
Dim loX As Long
Dim loForm As Form
On Error Resume Next
Set loForm = Screen.ActiveForm
If Err <> 0 Then
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If
If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
MsgBox "Cannot minimize Access with " _
& (loForm.Caption + " ") _
& "form on screen"
ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
MsgBox "Cannot hide Access with " _
& (loForm.Caption + " ") _
& "form on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
End If
fSetAccessWindow = (loX <> 0)
End Function
我如何临时反转/禁用 On Load 代码,但仅在运行报告时,或者可能有另一种查看报告的方法,而 Access 被 On Load 代码隐藏时可以工作?