Results 1 to 7 of 7
  1. #1
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141

    Open Form Hide Access


    I want a window (Form) to Open and hide the rest of Access. I have:
    Code:
    Private Sub Form_Open(Cancel As Integer)
    DoCmd.SelectObject acTable, , True
    DoCmd.RunCommand acCmdWindowHide
    End Sub
    This just hides the Navigation Pane

    Then when the Form is closed I want Access to come back
    Code:
    Private Sub Form_Close()
    DoCmd.SelectObject acTable, , True
    DoCmd.RunCommand acCmdWindowShownormal
    End Sub
    I get error on Shownormal
    But if I press stop in the VBA window - the form closes and shows access normally

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In the On Open event use:

    DoCmd.RunCommand acCmdWindowHide ' hides the navigation pane
    DoCmd.ShowToolbar "ribbon", acToolbarNo ' hides the ribbon

    and in the On Close event use:

    DoCmd.ShowToolbar "ribbon", acToolbarYes ' Restores the ribbon
    DoCmd.SelectObject acForm, "", True ' Restores the navigation pane

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    John_G's given you working code, but FYI, the reason

    DoCmd.RunCommand acCmdWindowShownormal

    popped an error is that

    acCmdWindowShownormal

    is not a valid Command, at least not through v2007, and I can find no reference to it anywhere, for later versions.

    If you enter this kind of thing manually, as was done here by you, or by someone else (if you did the old 'copy and paste routine') rather then using IntelliSense (the autocomplete function in the Access VBA IDE) when you move off of the line of code the Access Gnomes will capitalize the beginning character of each word in the Command. So your

    DoCmd.RunCommand acCmdWindowShownormal

    would have become

    DoCmd.RunCommand acCmdWindowShowNormal

    The fact that this didn't occur, in this case, tells you that it wasn't a legitimate Command, which makes this a good test for the legitimacy of a Command that is entered 'freehand.'

    Best policy, of course, unless you write this kind of code all the time, and I mean all the time, is to always use IntelliSense. When you type in DoCmd.RunCommand and hit the Space Key, a box will pop up with a list of all of the legitimate Commands.

    Linq ;0)>

  5. #5
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    Yes it was cut and paste - so I went to the code that June7 linked. I think I followed the steps exactly
    But the VBA gets the error Sub or Function not defined with line that begins public function fAccesswindow... highlighted
    Code:
    Sub basAccessHider()
    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
    Note: Both lines that read Private declare function... are in red font

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    That code will not compile. You cannot declare a function inside a Sub, and the code you show has no End Sub line, either.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Remove the line Sub basAccessHider().

    basAccessHider is supposed to be name of the module, not a Sub. This would be the name that shows in the Navigation pane for Access and the project list window of VBA editor. But name the module whatever you want.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-02-2014, 01:31 PM
  2. Replies: 6
    Last Post: 10-30-2013, 02:47 PM
  3. Open form only, hide the ribbon bar.
    By kcmiuser in forum Access
    Replies: 3
    Last Post: 05-22-2013, 02:04 PM
  4. Open Report and Hide Control using VBA
    By tylerg11 in forum Reports
    Replies: 4
    Last Post: 08-09-2012, 12:42 PM
  5. How do i open a form and hide a field?
    By xwnoob in forum Forms
    Replies: 1
    Last Post: 01-05-2012, 03:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums