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?
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
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.
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...
SixHatHideWindow(0)
–
Redeemable 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.
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
see this solution in
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
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
© 2022 - 2024 — McMap. All rights reserved.