Show Database Window after Hide

Epic

Registered User.
Local time
Today, 01:16
Joined
Dec 23, 2004
Messages
58
I have an ms access 2013 db on a WIN 10 64 bit machine.

What I'm trying to achieve is to have my login form showing up without the database window frame, just the form alone, then (after login) restore the database window.

I am using this code I found somewhere:
Code:
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3

Private Declare PtrSafe 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

My problem is that, when I restore (normal or maximized) it shows the window frame but nothing inside: ribbon, tables, etc... all gone.

Probably is an api issue but do you guys have a better solution or how can I force somehow the window to refresh/show missing elements?
 
Look for the sample code "restore access" to restore the window, ribbon etc.

If you set the login form to be a popup form, it doesn't need the Access database window. The form will be displayed outside the Access main window.

HTH:D
 
I'm getting an error - see the attached screenshot. Do I need to add something in references? Thanks in advance.
 

Attachments

  • apiShowWindow Error.png
    apiShowWindow Error.png
    43.3 KB · Views: 538
Bill - please only ask your question once, and can you start a new thread with a description of what you are trying to accomplish and how the failure you have pictured is caused.

There is no context with either of your two posts so far.

Also please post the actual code rather than a picture - we aren't clever enough to spot a typo in a jpeg. Press the advanced editor option and use the code tags (# symbol)
 
Thanks. I'll start a new thread with your suggestions if you think that's better, but I realized the highlights were missing on the screenshot so I took another. this was on the net and is supposed to hide the Access window if you call it from form_load on the initial form. I haven't used forums much so accept my apologies for klutziness.

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 PtrSafe 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
 

Attachments

  • apiShowWindow Error.png
    apiShowWindow Error.png
    42.6 KB · Views: 464
Epic / Bill,

I inherited a Access application that did just this. The previous guy did a fairly decent job with it but he did not have a robust error handler system. The result, frequently corrupted tables on the backend and other issues...mostly user induced.

My advice...stay away from this concept, the juice just ain't worth the squeeze.
 
Thanks - it just may end up that way. It'd be cool if I could get it to work, but I've spent over an hour on it already, and the functionality works perfectly well with Access open, so I may have to take your advice.
 
Hi

Bit late to this thread...!
If you're still interested, the following works perfectly for me..
Its similar to the code you posted but much simpler.

The code was written years ago by Dev Ashish.
I've added code to adapt it for 64-bit Office - just omit the sections in RED if not relevant to you.

In contrast to a previous post, this has NEVER caused any problems & is in widespread use

In the start up form, just add the following code in Form_Load event

Code:
SetAccessWindow (SW_HIDE)

You need the following code in a module.

Code:
Option Compare Database
Option Explicit

' 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

[COLOR="Red"]#If VBA7 Then
    Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
#ElseIf Win64 Then 'need datatype LongPtr
    Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As LongPtr, ByVal nCmdShow As LongPtr) As LongPtr
#Else '32-bit Office[/COLOR]
    Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
[COLOR="red"]#End If[/COLOR]

Function SetAccessWindow(CmdShow As Long)

'Usage Examples
'Maximize window:
' ?SetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?SetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
' ?SetAccessWindow(SW_HIDE)
'Normal window:
' ?SetAccessWindow(SW_SHOWNORMAL)
'
    Dim loX As Long
    
    On Error Resume Next

    loX = apiShowWindow(hWndAccessApp, CmdShow)
    SetAccessWindow = (loX <> 0)

End Function

To display the window again at any time, use one of these
Code:
SetAccessWindow(SW_SHOWNORMAL)

Code:
SetAccessWindow(SW_SHOWMAXIMIZED)
 

Attachments

  • FloatingSplashScreen.gif
    FloatingSplashScreen.gif
    58.6 KB · Views: 467
It is a nice piece of code.

I played with it but after a combination of

?SetAccessWindow(SW_SHOWMINIMIZED)

followed by

?SetAccessWindow(SW_HIDE)

followed by

?SetAccessWindow(SW_SHOWMAXIMIZED)

or any other command to show the Access window the result is an empty window.
All controlbars, navigation pane, menu functionality, right click functionality is gone.

I haven't tried to use it on a real live program. So i am not sure how it affects the program flow.
I seems that SW_HIDE screws up the Access window.

Restarting Access resets everything so that's not an issue.

If the program flow is not comprimised, the combination of these commands can be used to shield Access default functionality from the users.

If you've tried it let me know.

HTH:D

BTW: tested on Acc2010
 
I went to try this code out and received an error message that some variables were ambiguous?
Turns out I already had this, just not used it. No idea as to where I got it from, nor if it works time and time again, but seems slightly different?

HTH

Code:
Option Compare Database
Option Explicit
Option Base 0

'==============================
'  CONSTANTS FOR DBASE WINDOW
'==============================
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
 
'==========================
'  DBASE WINDOW FUNCTIONS
'==========================
#If VBA7 Then
Public Declare PtrSafe Function IsWindowVisible Lib "user32.dll" _
        (ByVal hWnd As Long) _
    As Long
Public Declare PtrSafe Function ShowWindow Lib "user32" _
        (ByVal hWnd As Long, _
        ByVal nCmdShow As Long) _
    As Long
#Else
Public Declare Function IsWindowVisible Lib "user32.dll" _
        (ByVal hwnd As Long) _
    As Long
Public Declare Function ShowWindow Lib "user32" _
        (ByVal hwnd As Long, _
        ByVal nCmdShow As Long) _
    As Long

#End If
 
'============================
' FORM MANAGEMENT FUNCTIONS
'============================
 
Public Function fAccessWindow(Optional Procedure As String, _
    Optional SwitchStatus As Boolean, Optional StatusCheck As Boolean) As Boolean
'****************************************************************************************
'* Purpose:  Controls the behavior and appearance of the Daatabase window               *
'*           residing on the form, and hence, we reduce the overall size of the FE DB.  *
'* Accepts:  Procedure -    describes the behavior requested                            *
'*           SwitchStatus - (optional) instructs the procedure to switch the current    *
'*                          status of the DB Window                                     *
'*           StatusCheck -  (optional) allows the procedure to check the current status *
'*                          of the DB window to determine whether or not to initiate a  *
'*                          change                                                      *
'****************************************************************************************
On Error GoTo EH
    Dim dwReturn As Long
    Select Case Procedure
        Case "Hide"
            dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
        Case "Minimize"
            dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMINIMIZED)
        Case "Normal"
            dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWNORMAL)
        Case "Show"
            dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
    End Select
    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
    Exit Function
EH:
    MsgBox "There was an error resetting the Database Window!  " & _
        "Please contact your Database Administrator.", vbCritical, "Error!"
    Exit Function
End Function
 
Public Function RestoreForm(FormName As String)
'**********************************************************************************
'* Purpose:  Manages the database window, keep the current form on top of others. *
'* Accepts:  FormName is the name of the Form which you want to restore           *
'* Returns:  N/A                                                                  *
'*   Usage:  Add "RestoreForm Me.Form.Name" to the OnOpen event of a form         *
'**********************************************************************************
On Error GoTo EH
    fAccessWindow "Minimize", False, False
    DoCmd.SelectObject acForm, FormName
    DoCmd.Restore
    Exit Function
EH:
    MsgBox "There was an error restoring the Form.  " & _
        "Please contact your Database Administrator.", vbOKOnly, "Error!"
    Exit Function
End Function
 
Hi

I'm away this week but on my return will provide a more detailed explanation of how to get around the problems described by Guus2005.
I use this with several databases used by teachers in more than one school and it works so smoothly that nobody has ever commented on it

If anyone here can remember back to British Leyland cars in the 1980s, BL spent millions developing bumpers the same colour as the car body and nobody noticed.... well its a bit like that, it just works!
 
Epic / Bill,

I inherited a Access application that did just this. The previous guy did a fairly decent job with it but he did not have a robust error handler system. The result, frequently corrupted tables on the backend and other issues...mostly user induced.

My advice...stay away from this concept, the juice just ain't worth the squeeze.


I totally agree.

Why do something that is guaranteed to be a never ending source of issues and a support headaches.nightmare.

Ask yourself:
Does this really make the application better for the end users?
Do the end users really care?

If the answer to either is NO then you probably should not waste the time and money doing it.

IMHO, application designers and developers should put all their efforts into making the parts of the application the users spend the most time using better.
 
I totally agree.

Why do something that is guaranteed to be a never ending source of issues and a support headaches.nightmare.

Ask yourself:
Does this really make the application better for the end users?
Do the end users really care?

If the answer to either is NO then you probably should not waste the time and money doing it.

IMHO, application designers and developers should put all their efforts into making the parts of the application the users spend the most time using better.

Whilst accepting the principle behind HiTech's comment, my response was intending to make the point that it has been totally trouble free and therefore doesn't get commented on. The only time people tend to comment is when something goes wrong.

As I said in last post, i'll explain further when I'm back from holiday next weekend.
 
I have created an example database to show how the Access application interface can be controlled in various ways.
Some of these methods can be used to make a database more secure.

It is intended to demonstrate that all of this is easy to do safely and without any issues arising

The item can be found in: https://www.access-programmers.co.uk/forums/showthread.php?t=293584
EDIT. 17/09/2018: INCORRECT LINK NOW FIXED

The database is opened with form frmStart 'floating independently' on the desktop i.e. with the access application window hidden

Buttons on the form can be used to:
- show / hide entire Access application window
- show / hide navigation pane
- show / hide ribbon
- show / hide taskbar
- maximise the form to fill the entire screen (no title bar & no taskbar)
- open another form with a related report. This shows how the print preview ribbon can be displayed whilst the report is open & hidden when it is closed
- open / close the VBE

Although it is highly unlikely that any single application would need to use all of these features, this is designed to show that all items can be toggled on / off independently without problems.

All code has been fully tested in Access 2010 & 2016.
In addition, each section of the code has been widely used in various production databases for several years.
 

Attachments

  • SetWindowsApp.gif
    SetWindowsApp.gif
    46.2 KB · Views: 441
Last edited:
Broken link.

Was this something you just posted or was it an older thread?
 
Broken link now fixed.
Item was moved to Sample databases. My fault!
 
Last edited:
Hi Alvin

I've just fixed the link which was incorrect due to items being moved a few months ago.

The link you quoted is for fixing errors in the system table MSysObjects.
EDIT: I have checked that & it runs perfectly in 64-bit Access.
There are compile errors in the application but that is intentional as the file contains errors and shows how to correct them.

If you want the sample database to control the application interface, the correct link is now shown in post 14.
The attachments in posts #3 and #6 of that thread do work in 64-bit Access
 
Last edited:

Users who are viewing this thread

Back
Top Bottom