hWnd Property Help Example gives Run-time error 2475 in Access but not in VB6

S

septim

Why am I getting Run-time error 2475 when I try this
Access Help Example in Access? I don't get this run-time
error in Visual Basic 6 Professional.

When I tried the following Access Help Example in either
an Access form or a Visual Basic form, I got the "Declare
statements not allowed as Public members of object
modules" message. So I added the Private keyword.

After changing "Declare" to "Private Declare" I got "Run-
time error '2475': You entered an expression that requires
a form to be the active window" when running the form in
Access. To try this in a Visual Basic 6 Professional form,
I replaced DoCmd.Maximize with WindowState = 2 and that
works.

The following is copied verbatim from Access Help:
-------------------------------------------------
The following example uses the hWnd property with the
Windows API IsZoomed function to determine if a window is
maximized.

' Enter on single line in Declarations section of Module
window.
Declare Function IsZoomed Lib "user32" (ByVal hWnd As
Long) As Long

Sub Form_Activate()
Dim intWindowHandle As Long
intWindowHandle = Screen.ActiveForm.hWnd
If Not IsZoomed(intWindowHandle) Then
DoCmd.Maximize
End If
End Sub

I also got Run-time error 2475 in Access with this code:
-------------------------------------------------------
Private Declare Function IsZoomed Lib "user32" (ByVal hWnd
As Long) As Long
Private blnWasMaximized As Boolean
Sub Form_Activate()
Dim lngWindowHandle As Long
lngWindowHandle = Screen.ActiveForm.hWnd
' The IsZoomed function returns True if a window is
maximized
If IsZoomed(lngWindowHandle) Then
blnWasMaximized = True
DoCmd.Restore
End If
End Sub

Private Sub Form_Deactivate()
If blnWasMaximized = True Then DoCmd.Maximize
End Sub
 
D

Dirk Goldgar

septim said:
Why am I getting Run-time error 2475 when I try this
Access Help Example in Access? I don't get this run-time
error in Visual Basic 6 Professional.

When I tried the following Access Help Example in either
an Access form or a Visual Basic form, I got the "Declare
statements not allowed as Public members of object
modules" message. So I added the Private keyword.

After changing "Declare" to "Private Declare" I got "Run-
time error '2475': You entered an expression that requires
a form to be the active window" when running the form in
Access. To try this in a Visual Basic 6 Professional form,
I replaced DoCmd.Maximize with WindowState = 2 and that
works.

The following is copied verbatim from Access Help:
-------------------------------------------------
The following example uses the hWnd property with the
Windows API IsZoomed function to determine if a window is
maximized.

' Enter on single line in Declarations section of Module
window.
Declare Function IsZoomed Lib "user32" (ByVal hWnd As
Long) As Long

Sub Form_Activate()
Dim intWindowHandle As Long
intWindowHandle = Screen.ActiveForm.hWnd
If Not IsZoomed(intWindowHandle) Then
DoCmd.Maximize
End If
End Sub

I also got Run-time error 2475 in Access with this code:
-------------------------------------------------------
Private Declare Function IsZoomed Lib "user32" (ByVal hWnd
As Long) As Long
Private blnWasMaximized As Boolean
Sub Form_Activate()
Dim lngWindowHandle As Long
lngWindowHandle = Screen.ActiveForm.hWnd
' The IsZoomed function returns True if a window is
maximized
If IsZoomed(lngWindowHandle) Then
blnWasMaximized = True
DoCmd.Restore
End If
End Sub

Private Sub Form_Deactivate()
If blnWasMaximized = True Then DoCmd.Maximize
End Sub

The Declare for IsZoomed must go in the Declarations section of a
standard module, not the form's module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top