我将 Access 2007 用于我的 Access 2003 MDB 项目,并且在尝试显示查询结果时遇到了一些问题。这里没什么特别的:
DoCmd.OpenQuery "myQuery", acViewNormal
以简单的形式,它工作得很好。但是,我使用以下代码隐藏了后台访问窗口:
Private Declare Function apiShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3
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
我显然可以调用 fSetAccessWindow(1) 来恢复完整的界面,但我想在这里只显示查询结果而不是 Access 的完整界面。是否可以?一些用户使用批处理文件运行数据库(不确定它是否会产生任何影响):
start msaccess /runtime "myFile.mdb"
另外,因为我所有的表单都是模态的(必须是在没有界面或窗口不显示的情况下工作),查询结果显示在后台,没有任何方式设置焦点(用户必须关闭活动应用程序窗口这样做)。