compile error 64 bit (1 Viewer)

tubar

Registered User.
Local time
Today, 04:31
Joined
Jul 13, 2006
Messages
190
Im using a module to hide access in the background from the user. It worked for years till today when i received a compile error. The code in this project must be updated for use on 64-bit. please update declare statement and mark them with PtrSafe attribute. Any know what i need to insert. The complete module is
Code:
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

' This function is to be called as such:
' Call fSetAccessWindow (argument)
' The arguments are as follows;
' SW_HIDE - this hides the access database window
' SW_SHOWMAXIMIZED - this maximizes the window
' SW_SHOWMINIMIZED - this minimizes the window
' SW_SHOWNORMAL - this just shows (as normal) the window


Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
' ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
' ?fSetAccessWindow(SW_HIDE)
'Normal window:
' ?fSetAccessWindow(SW_SHOWNORMAL)
'
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

The Code in red is

Code:
Private Declare Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long

i changed the code in red to this
Code:
#If Win64 Then
    Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As LongLong, lpRect As typRect) As LongLong
#Else
    Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, lpRect As typRect) As Long
#End If
But now i get user defined type not defined
 
Last edited:

tubar

Registered User.
Local time
Today, 04:31
Joined
Jul 13, 2006
Messages
190
Ive added PtrSafe to the declaration statements, unless im missing something
Code:
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
#If Win64 Then
    Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As LongLong, lpRect As typRect) As LongLong
#Else
    Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, lpRect As typRect) As Long
#End If



' This function is to be called as such:
' Call fSetAccessWindow (argument)
' The arguments are as follows;
' SW_HIDE - this hides the access database window
' SW_SHOWMAXIMIZED - this maximizes the window
' SW_SHOWMINIMIZED - this minimizes the window
' SW_SHOWNORMAL - this just shows (as normal) the window


Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
' ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
' ?fSetAccessWindow(SW_HIDE)
'Normal window:
' ?fSetAccessWindow(SW_SHOWNORMAL)
'
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:31
Joined
May 7, 2009
Messages
19,169
Code:
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

#If VBA7 Then
    #If Win64 Then
        Public Declare PtrSafe Function ShowWindow Lib "user32" _
                (ByVal hWnd As LongPtr, _
                ByVal nCmdShow As Long) _
            As Long
    #Else
        Public Declare PtrSafe Function ShowWindow Lib "user32" _
                (ByVal hWnd As Long, _
                ByVal nCmdShow As Long) _
            As Long
    #End If
#Else
    Public Declare Function ShowWindow Lib "user32" _
            (ByVal hWnd As Long, _
            ByVal nCmdShow As Long) _
        As Long
#End If

' This function is to be called as such:
' Call fSetAccessWindow (argument)
' The arguments are as follows;
' SW_HIDE - this hides the access database window
' SW_SHOWMAXIMIZED - this maximizes the window
' SW_SHOWMINIMIZED - this minimizes the window
' SW_SHOWNORMAL - this just shows (as normal) the window

#if win64 then
Function fSetAccessWindow(nCmdShow As LongPtr)
#else
Function fSetAccessWindow(nCmdShow As Long)
#end if
'Usage Examples
'Maximize window:
' ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
' ?fSetAccessWindow(SW_HIDE)
'Normal window:
' ?fSetAccessWindow(SW_SHOWNORMAL)
'
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
 

tubar

Registered User.
Local time
Today, 04:31
Joined
Jul 13, 2006
Messages
190
Thanks ARNELGP!!!!

After using your revised code i i get a Compile error sub or function not defined.
with apiShowWindow highlighted
Code:
If Err <> 0 Then
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.clear
End If
any help would be appreciated. And thanks for your help so far!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:31
Joined
May 7, 2009
Messages
19,169
replace apiShowWindow with just ShowWindow
 

Users who are viewing this thread

Top Bottom