fAccessWindow(“Hide”,False,False)给出编译错误

时间:2011-03-09 22:29:59

标签: ms-access macros ms-access-2010

fAccessWindow(“Hide”,False,False)隐藏实际访问窗口的函数给出了编译错误号7960

我试过没有空间“fAccessWindow(”隐藏“,假,假)”但没有区别。我还在一个模块中有下面的代码,也可以找到here。我正在使用具有最低宏安全级别的Access 2010。我的操作系统也是x64。

Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Dim dwReturn As Long

Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
     ByVal nCmdShow As Long) As Long

Public Function fAccessWindow(Optional Procedure As String, Optional SwitchStatus As Boolean, Optional StatusCheck As Boolean) As Boolean
If Procedure = "Hide" Then
    dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
End If
If Procedure = "Show" Then
    dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
End If
If Procedure = "Minimize" Then
    dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMINIMIZED)
End If
If SwitchStatus = True Then
    If IsWindowVisible(hWndAccessApp) = 1 Then
        dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
    Else
        dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
    End If
End If
If StatusCheck = True Then
    If IsWindowVisible(hWndAccessApp) = 0 Then
        fAccessWindow = False
    End If
    If IsWindowVisible(hWndAccessApp) = 1 Then
        fAccessWindow = True
    End If
End If
End Function

2 个答案:

答案 0 :(得分:2)

您需要引用this article from MS on 64-bit VBA并且不仅使用PtrSafe,还要使用新的LongLong数据类型,并且您需要使用条件编译:

  #if Win64 then
      Private Declare PtrSafe Function IsWindowVisible Lib "user32" (ByVal hwnd As LongLong) As LongLong
  #else
      Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
  #end if

我不是为64位Access编程,所以没有使用它。我不清楚Win64和VBA7编译常量之间的相互作用是什么,引用的文章并不完全清楚。我不清楚你是否应该这样做:

  #If Win64 And VBA7 Then
      ...
  #Else
      ...
  #End If

或者应该是:

  #If Win64 Then
      #If VBA7 Then
         ...
      #Else
         ...
      #End If
  #Else
      #If VBA7 Then
         ...
      #Else
         ...
      #End If
  #End If

答案 1 :(得分:0)

我已经在下面的函数中添加了PtrSafe选项,它开始在x64中运行,但现在它在x86机器上给出了同样的错误。

Private Declare PtrSafe Function IsWindowVisible Lib "user32"_
    (ByVal hwnd As Long) As Long

Private Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
    ByVal nCmdShow As Long) As Long