3

While starting up my MS Access 2013 database, I only need it to show the startup form and nothing else. Desired result would be something like below. The background is my desktop.

Desired:

enter image description here

However when I open the DB, the form opens taking the entire screen.

The below VBA code runs when the startup form loads and initially it works, but if I minimize the window I can see the background again.

Option Compare Database
Option Explicit
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)
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
fSetAccessWindow = (loX <> 0)
End Function

I have hidden ribbons, navigation pane and all access user interfaces, but I need to remove the Access background also.

Current:

enter image description here

Any help / advice would be appreciated. Thanks in advace !!!

Tomislav Stankovic
  • 3,080
  • 17
  • 35
  • 42

2 Answers2

9

You don’t need any API code.

The following settings should do the trick:

File->Options->Current Database

Uncheck “Display document tabs” Choose Tabbed Documents.

In above also un-check Display navigation Pane.

To hide the ribbon, execute this ONE line of VBA in your startup:

DoCmd.ShowToolbar "Ribbon", acToolbarNo

The resulting screen will be this:

enter image description here

Make sure the form(s) are not dialog, and make sure they are not popup forms.

To go back into “development” mode, you exit the database and then re-launch holding down the shift key – that will by-pass all of the above and allow you to develop.

Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51
  • What if you want to have different forms of different sizes? is there a way to get the whole window to re-size with the different forms? – Isaac Reefman Jan 18 '19 at 05:56
  • Launching Word, Excel, a web browser NEVER re-sizes the application window. Even an accounting system with 200+ forms does NOT re-size the main application window. Never seen ANY software in the last 20 years that works as you describe. The size of the application will take on the size of the first form launched. For 99% of applications I EVER used then the main UI window provides menus, tabs or navigation bars across the top or down the side. One could perhaps re-size the application window to each form launched, but that’s rather jerky and a rather rotten type of UI I have NEVER seen before – Albert D. Kallal Jan 18 '19 at 19:04
0

I use synchronization of main form and Access windows sizes, so Access window will be always behind main window. Here is code behind:

Private Sub Form_Resize()
'main form
'Let us know when Form is Maximized...

If CBool(IsZoomed(Me.hwnd)) = True Then
    funSetAccessWindow (SW_SHOWMAXIMIZED)
    DoCmd.Maximize
    Me.TimerInterval = 0
ElseIf CBool(IsIconic(Me.hwnd)) = True Then
    funSetAccessWindow (SW_SHOWMINIMIZED)
    Me.TimerInterval = 0
Else
    'enable constant size sync
    Me.TimerInterval = 100
    SyncMainWindowSize Me, True
End If
End Sub

Private Sub Form_Timer()
SyncMainWindowSize Me
End Sub

Public Function SyncMainWindowSize(frm As Form, Optional blnForce As Boolean = False)
Dim rctForm As RECT
Dim iRtn As Integer
Dim blnMoved As Boolean

Static x As Integer
Static y As Integer
Static cx As Integer
Static cy As Integer

#If VBA7 And Win64 Then
    Dim hWndAccess As LongPtr
#Else
    Dim hWndAccess As Long
#End If

If GetWindowRect(frm.hwnd, rctForm) Then
    If x <> rctForm.Left Then
        x = rctForm.Left
        blnMoved = True
    End If

    If y <> rctForm.Top Then
        y = rctForm.Top
        blnMoved = True
    End If
    If cx <> rctForm.Right - rctForm.Left Then
        cx = rctForm.Right - rctForm.Left
        blnMoved = True
    End If
    If cy <> rctForm.Bottom - rctForm.Top Then
        cy = rctForm.Bottom - rctForm.Top
        blnMoved = True
    End If

    If blnMoved Or blnForce Then
        'move/resize main window
        hWndAccess = Application.hWndAccessApp
        iRtn = apiShowWindow(hWndAccess, WM_SW_RESTORE)
        Call SetWindowPos(hWndAccess, 0, x, y, cx, cy, WM_SWP_NOZORDER Or WM_SWP_SHOWWINDOW)
    End If
End If
End Function

Function funSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
'       ?funSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
'       ?funSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
'       ?funSetAccessWindow(SW_HIDE)
'Normal window:
'       ?funfSetAccessWindow(SW_SHOWNORMAL)
    Dim loX  As Long
    On Error GoTo ErrorHandler

    loX = apiShowWindow(hWndAccessApp, nCmdShow)
    funSetAccessWindow = (loX <> 0)
End Function
Sergey S.
  • 6,296
  • 1
  • 14
  • 29