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

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 verbatum 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



Fri, 09 Dec 2005 23:59:18 GMT  
 hWnd Property Help Example gives Run-time error 2475 in Access but not in VB6

Quote:
> 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 verbatum 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

First, you should put the declaration of IsZoomed into a standard
module, not in the form's module.  Then you can declare it as Public and
use it in multiple forms.

Second, it appears that when you first open the form, its Activate event
fires before Screen.ActiveForm has been set.  My experiments show that
if you switch the focus away from the form and then back to it, the code
works.  You can get around this problem by dropping the use of
Screen.ActiveForm completely, and using the form's hWnd property
directly instead:

    Sub Form_Activate()

        Dim lngWindowHandle As Long

        lngWindowHandle = Me.hWnd

        If Not IsZoomed(lngWindowHandle) Then
            DoCmd.Maximize
        End If

    End Sub

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)



Sat, 10 Dec 2005 03:30:27 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. running examples with web browser control give error

2. Help Me:give me some examples about Updatable property

3. Registry access error (Not able to perform the operation because object is not given storage yet)

4. Accessing design time properties in run time

5. Win16 API, getting control properties given hwnd

6. Help on run-time error with VB6.0 and ADOCE3.0

7. Help: Run-Time error 5 in VB6

8. Run-Time Error 3251, What Gives!

9. Can anyone help with Run Time Error 713 (Class not registered)

10. Run Time error - Path Not Found - HELP!

11. why does my ie give run time error

12. Object Variable not set , Run Time error 91, please Help

 

 
Powered by phpBB® Forum Software