Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7654
  • Last Modified:

hide access window, dislay popup form

Hi experts
I’m trying to hide the main database window but still display a popup form on screen.

I found some code here

That claims to be able to do this.

This example is supposed to hide the main access window by calling
fSetAccessWindow (SW_HIDE) as the argument, called from a popup form. With the function called via a TimerEvent fired by the form open event

But both the main window AND the popup form both disappear,
what am I doing wrong ?

Here is the code snippet from the above link

API: Manipulate Access Window
Author(s)  Dev Ashish
(Q) How do I maximize or minimize the main Access Window from code?
(A) Pass one of the declared constants to the function fSetAccessWindow.

This same function can also be used to completely hide Access window and just show your form on the desktop. Make the form popup and from it's Open Event, call the fSetAccessWindow function with SW_HIDE as the argument.

Warning: If you're hiding the main Access window, make sure your error handlers are good. Because with the window hidden, if an error is raised, pressing "End" on the Error window will NOT make Access window visible and you will be left with just the form open. A recommended method is to make a call to fSetAccessWindow with SW_SHOWNORMAL from your error handlers.
If, for some reason, the Access window does not show itself, then you can always close the mdb from the Task List, available in Win 95 with Control-Alt-Delete (once) and under NT, by right clicking on the Taskbar and selecting Task Manager, by selecting the mdb and clicking End Task.

'************ Code Start **********
' 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

Private Declare Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long

Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
' ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
' ?fSetAccessWindow(SW_HIDE)
'Normal window:
' ?fSetAccessWindow(SW_SHOWNORMAL)
Dim loX As Long
Dim loForm As Form
On Error Resume Next
Set loForm = Screen.ActiveForm
If Err <> 0 Then 'no Activeform
If nCmdShow = SW_HIDE Then
MsgBox "Cannot hide Access unless " _
& "a form is on screen"
loX = apiShowWindow(hWndAccessApp, nCmdShow)
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"
loX = apiShowWindow(hWndAccessApp, nCmdShow)
End If
End If
fSetAccessWindow = (loX <> 0)
End Function

'************ Code End **********
1 Solution
I have been using this code successfully for years. All forms must be popups.
DBDavegAuthor Commented:
yes my forms ARE popup
as I said above "But both the main window AND the popup form both disappear, "
Then your code must be encountering an error, in the beginning of the code add
on error goto errhandler

Open in new window

and at the end add
call fSetAccessWindow(1)
msgbob err.number & vbcrlf & err.description

Open in new window

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Dale FyeCommented:
No points please.

I have used that code several times as well, and agree with MacroShadow the in design mode (Other tab of the Properties dialog), the form must defined as Popup = Yes.

Don't use it much any more except for extremely simple applications that only involve a couple of forms.
Where are you calling the "hide" function?

I use it successfully and I put it in the On_Open event of my opening form (switchboard).

When in design mode, do NOT open this form.... or else simply rem it out while you are designing.  If you try to open the form (in design mode) Access will disappear and you'll have to use the TASK MANAGER to stop it from running.

Scott C
You should also turn on to the Modal

   Me.PopUp = True
   Me.Modal = True

If the Modal is off, the popup form will hide.

(Don't forget to add on close button that when the user will close the form it should Quit to full application, if not MSACCESS will stay running in the background.)
DBDavegAuthor Commented:
awesome thanks Gozreh that fixed it
working like a dream now, so simple a fix
I now see that it works if you make the form acDialog too.

why didn't they just mention Modal in the code instructions ?? instead of just popup
many thanks

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now