Hide access window when opening a form
Asked Answered
A

7

8

My Access database has an autoexec macro which opens a main menu (Form). All necessary functions are menu (form)-controlled, and I want to hide the Access Window so that only the forms are displayed. I was referred to http://www.tek-tips.com/faqs.cfm?fid=2562 but this doesn't work with later versions. Is there a snippet which will work for Access 2007-2013?

Actium answered 10/4, 2016 at 9:33 Comment(1)
I'm not sure what that did, but it worked. thanksActium
C
7

This is the code I run in my Acc 2003 and 2007 Apps, running in 2010 environment:

Private Sub Form_Load()
   'Hide Data-Base Window:
   DoCmd.SelectObject acTable, , True
   DoCmd.RunCommand acCmdWindowHide
  '...Other Actions...
end sub

For hiding the ribbon in 2007 and higher use this line I found here:

DoCmd.ShowToolbar "Ribbon", acToolbarNo
Cinchonidine answered 10/4, 2016 at 13:8 Comment(3)
This is perfect. Just a simple command. I looked for another similar command to hide the ribbon , but couldn't find anything. Is this possible?Actium
@Robert Kendall I added the line of code to the answerCinchonidine
Thanks for the Ribbon trick. In Access 2016, the old "AllowFullMenus" and "AllowBuiltInToolbars" didn't hide the file menu and the help menu.Construe
C
3

It seems your goal is to restrict the Access UI features which are available to the user of your database. You want to limit them to the options which you provide via your startup form.

In that case, take a copy of your ACCDB file and change its file extension to ACCDR. Then when you open the ACCDR from Windows Explorer, Access will open it in "runtime mode". Runtime mode suppresses most of the standard UI options. For example, the Navigation pane is not displayed, and can't even be opened. Also it gives you a very minimal version of the Ribbon; the majority of the standard Ribbon options are gone.

Runtime mode has other consequences which you should investigate to see whether it's a good fit for your needs. One important issue is runtime mode will quit the application when an unhandled error is encountered.

If ACCDR/runtime mode suits your particular situation, it is an inexpensive way to limit the database UI features. However, beware a user could make a copy of the ACCDR and change the file extension back to ACCDB, so this approach alone may not satisfy your security requirements.

Conklin answered 10/4, 2016 at 16:20 Comment(1)
You can also create an accde file, and run it with the "/excl /runtime" command line switches. The first one opens it in exlusive mode, so Access skips multiuser environment checks, and the second limits the users to runtime options. An attacker will be able to copy tables and queries from accde to a new accdb, but forms and vba code will be protected. It is possible to bypass this protection, but not in a trivial way.Construe
D
2

This is what I use that works up to 2016:

Option Compare Database
Option Explicit

'''HIDE WINDOW MODULE
'''USE THIS TO ACTIVATE HIDE WINDOW MODULE
''' SixHatHideWindow(SW_SHOWMINIMIZED)

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 SixHatHideWindow(nCmdShow As Long)
    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
    SixHatHideWindow = (loX <> 0)
End Function

To Hide the Window Simply: Call SixHatHideWindow(SW_SHOWMINIMIZED)

ALSO NOTE: Depending on Which Version i.e. 32 bit or 64 bit you may need to add the PtrSafe attribute so If you are having issues with this Declare the API Function like this: Private Declare PtrSafe Function apiShowWindow...

Degradation answered 10/4, 2016 at 10:22 Comment(8)
I pasted this and added a button to run the code: SixHatHideWindow(SW_SHOWMINIMIZED) but I get an error:"The object does not contain the automation object 'SW_SHOWMINIMIZED'"Actium
I've received this error with this same module before. It has always been because of compilation errors somewhere else. Do this; 1. Comment out this module you just added... then compile and fix any errors that may pop up else where. If you do not find additional errors else where then Un-comment the module and compact and repair the database. That should hopefully resolve the issue.Degradation
Also note that you should Call the function on the Open Event of the form which triggers before the Load EventDegradation
When you say call the function, is that the same as running a macro with the action line: SixHatHideWindow(SW_SHOWMINIMIZED) ?Actium
In a sense yes... I usually do not use Macro's anymore myself but all they do in the end is produce your VBA Code for you. I've never triggered this function from an AutoExec Macro... but it still should work. I think the issue you are having may be due to the other Module you were trying to use in hiding the Window... If it had issues like you said then it may not compile. Did you compile like I suggested?Degradation
For use with a macro, call the function with a number, like: SixHatHideWindow(0)Redeemable
when stepping through SixhatHideWindow(0) it steps into the if error... and on the loX= step, the whole window minimizes, including the active form, which I want to stay visible. And yes, I added the PTRSafe commandActium
I added an enumeration: Public Enum uShowWindowMode SW_HIDE = 0 SW_SHOWNORMAL = 1 SW_SHOWMINIMIZED = 2 SW_SHOWMAXIMIZED = 3 End Enum // Also: Function SixHatHideWindow(nCmdShow As uShowWindowMode)Kilderkin
G
1

Properly hiding the Access main window is a theme that pops up frequently. I have worked with the fSetAccesswindow approach outlined before, with a popup main form, over the years. The big disadvantage is that Access re-appears when the user minimizes the window then checks back , after which the Access window reappears. There is no event that captures that. I have now found the recipe that works best for me:

  • Make Main navigation form not a popup but normal, non-modal window

  • Start your main (navigation) form from a macro named Autoexec , instead of "form to start " from Options. Access will run that macro at startup. This a much better aproach than the "initial form" set in Access->File->options, because you can run the macro by doubleclicking during debug or development to start the main form.

  • In Acces->File->options: uncheck the "tabbed documents" That will hide the main form tab

  • In the MainForm_load event :

      DoCmd.ShowToolbar "Ribbon", acToolbarNo
      DoCmd.ShowToolbar "Status Bar", acToolbarNo
      Call DoCmd.NavigateTo("acNavigationCategoryObjectType")
      Call DoCmd.RunCommand(acCmdWindowHide)
    

This way, Access & your form become a single normal application window

I make a hidden button to re-surface Access when I need , that calls this code

DoCmd.ShowToolbar "Ribbon", acToolbarYes
DoCmd.ShowToolbar "Status Bar", acToolbarYes
Call DoCmd.SelectObject(acTable, , True)

Or, you can start the app with shift pressed, to prevent the macro to run.

Hope this helps.

Graciagracie answered 5/6, 2022 at 21:32 Comment(0)
C
0

I was seeking to accomplish hiding the Access application window and use popup forms that I could run from Outlook. That's how I ran across this post. But I found that with Outlook 2013 64bit on Windows 7 64bit one doesn't even need the SixHatHideWindow function. Using the following code in Outlook 2013 accomplishes the same thing. (Don't forget to add a reference to the Access object library in VBA.) This procedure saves the caption from the currently active Outlook window, starts a new hidden instance of Access (application window not visible), opens the designated Access database, runs the designated form (as visible), exits the Access instance when the form is closed, and re-activates the original Outlook active window. I have not tested this in any other environment nor with runtime Access.

The great thing about this approach is that it doesn't require that any special code be inserted in the form open event in the Access database. All the necessary code is contained in Outlook VBA. Nor do the database form's popup and modal properties need to be set to "Yes" in the database.

The form in this case is a complicated form with a tab control and several subforms. Everything appears to work whether the form is opened from Access itself or via automation from Outlook.

Note: The SetWindowPos api sets the location and size of the Access main window even though Access is not visible. When Access is closed, the next time the user opens Access it will re-open to the size and position set by the SetWindowPos api. This could be annoying to users, so the SetWindowPos api sets the Access application window to full screen size. The next time the user opens Access it will be maximized on their screen. There may be more sophisticated ways to handle this, but this approach is fast and easy, and most users work with Access maximized in most cases anyway.

Hope this helps someone out.

Private Declare PtrSafe Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal cX As Long, ByVal cY As Long, ByVal wFlags As Long) As Long
Private Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Sub OpenAccessFrmProjDetails()
      Dim accapp As Access.Application
      Dim HoldCaption As String
      Dim ScreenRect As RECT
      Dim ret As Long
      Dim width As Variant
      Dim height As Variant

      'Get the width and height of the screen in pixels
10    ret = GetClientRect(CLng(GetDesktopWindow()), ScreenRect)
20    width = ScreenRect.Right - ScreenRect.Left
30    height = ScreenRect.Bottom - ScreenRect.Top

      'Get Outlook activewindow caption
40    HoldCaption = ActiveWindow.Caption

      'Display the Access database form
50    Set accapp = New Access.Application
60    With accapp
70        .opencurrentdatabase ("C:\Users\pmf\Documents\Programming Development\Access Visibility Testing\Hidden.accdb")
80        SetWindowPos .hWndAccessApp, 0, 0, 0, width, height, 0
90        .DoCmd.OpenForm FormName:="frmProjDetails", WindowMode:=acDialog
100   End With

110   Set accapp = Nothing

      'Reactivate Outlook
120   AppActivate HoldCaption

110   End Sub
Casebook answered 11/11, 2016 at 5:21 Comment(2)
Why are you using line numbers? Those haven't been needed since GW-BASIC back in 1988.Klondike
@Klondike Remark: There is an erl object, wich contains the identifier of the line where the last error has occured in the current sub/function, but only if the identifier is numerical. I actually have a line numberer utility to use this information for error log.Construe
A
0

see this solution in

https://msaccess.erpmakers.com/Articles_MSAccess/0013-how%20to%20hide%20all%20access%20objects%20including%20navigation%20menu%20and%20ribbon%20using%20microsoft%20access%20vba.php

I tested the solution its work for me for acees 2016 with a little changement

I insert the content in module and call the function VerifyLoadApplication() in the created manually macro ExcAuto

Next, compile all code in vba editor -> debug-> compile and verify there is not an empty sub routine in all code vba ,to avoid not success convert acccdb in acccde

but i encounter a problem when and open accde file for the first time its work fine but for all next open file the home and file tab appeared

after a search on the web and tested the code locally and find this solution

'comment the two instructions

'CurrentDb.Properties("AllowFullMenus") = False
'CurrentDb.Properties("AllowBuiltInToolbars") = False

'and replace with this instrcution

DoCmd.ShowToolbar "Ribbon", acToolbarNo

you can do the same thing for the two like two instructions in the first party of the code with the true condition

Aparri answered 1/2, 2021 at 12:8 Comment(0)
K
0

Create a Desktop shortcut to the DB and set the "Run" property of the shortcut to "Minimized". Use this along with the code provided by @Michiel Steltman to truly hide the window in the taskbar. Add the following code to quit the form and the application:

Private Sub Form_Unload(Cancel As Integer)
    DoCmd.Quit
End Sub
Koto answered 5/2, 2023 at 5:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.