Results 1 to 7 of 7

Thread: open form alone

  1. #1
    Join Date
    Sep 2003
    Location
    Ft. Lauderdale, Florida
    Posts
    8

    Unanswered: open form alone

    i would like to use this code to hide the access window. i pasted this code in the general declarations and the pasted
    fSetAccessWindow(SW_HIDE) into on open form. when i open the form it says "Cannot hide Access unless form is on the screen. can someone tell me what i can do to make this work?
    By the way this was also a part of the code but im not sure where or how this following code works:

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



    This following code was written by Dev Ashish
    '************ Code Start **********
    ' This code was originally written by Dev Ashish.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' Dev Ashish
    '
    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

    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 'no Activeform
    If nCmdShow = SW_HIDE Then
    MsgBox "Cannot hide Access unless " _
    & "a form is on screen"
    Else
    loX = apiShowWindow(hWndAccessApp, nCmdShow)
    Err.Clear
    End If
    Else
    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
    End If
    fSetAccessWindow = (loX <> 0)
    End Function

    '************ Code End **********

  2. #2
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133
    Jigzacura,

    the solution is as simple as stupid :
    1. put the function call fSetAccessWindow(SW_HIDE) in the onload event of the form.
    2. your form must be a pop-up form (set its property POP UP to Yes)

    That should do the trick...

  3. #3
    Join Date
    Sep 2003
    Location
    Ft. Lauderdale, Florida
    Posts
    8
    Thanks for the reply Herman,
    i did that already. when i open the form it says
    "Cannot Hide Access unless a form is on the screen"

    *Edit: also i didnt put this part of the code anywhere because i didnt know where to put it:

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



    i thought it was that simple as well hehe.
    Thanks
    Shane
    Last edited by Jigzacura; 09-12-03 at 12:46.

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    ...because i didnt know where to put it:....
    the global constant declarations go exactly as shown... outside any sub/func in (and preferrably at the top of) a global module just after the Option declarations (if you have any)

    ...but that's not your basic problem, since you are getting the "correct" error return from Function apiShowWindow

    never tried this func, so just guessing:

    is it a timing problem?

    i.e. has "unless a form is on the screen" occurred when you call the func in the _Open?

    experiment: make a button on your form and in it's _Click()
    fSetAccessWindow(SW_HIDE)

    ...if that works, consider using some later event than _open ( _current for example)

    izy

  5. #5
    Join Date
    Sep 2003
    Location
    Ft. Lauderdale, Florida
    Posts
    8
    i put the command in the button _click but when i clicked it all it did was minimize the access window. it did not hide it. i used:
    fSetAccessWindow (SW_HIDE)

    Any other ideas?
    Thanks
    Shane

  6. #6
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133
    The code works, no doubt about that : I used it in several applications.

    You need to put the complete code in a general module and these lines in the OnLoad event of the form :

    'run application in minimised Access-view
    fSetAccessWindow (SW_SHOWMINIMIZED)
    DoCmd.RunCommand acCmdSizeToFitForm

    This does work for me, so I don't see why it shouldn't work for anyone else....

    I've tried your way : putting the code in a button and indeed it only minimises the form. That's why you must put the call for the function in the onload event!

    Try it!

  7. #7
    Join Date
    Sep 2003
    Location
    Nevada
    Posts
    8

    Cool THANKS Herman

    I've been following this post with interest as I had a copy of the same code "Jigzacura" has and was having the same problems.

    Thanks to Herman for his insite into this. With his pointers I have been able to get the code to work and the result is VERY pleasing.

    Thanks again Herman !!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •