?
Solved

hide access window, dislay popup form

Posted on 2014-02-05
7
Medium Priority
?
7,544 Views
Last Modified: 2014-02-06
Hi experts
I’m trying to hide the main database window but still display a popup form on screen.

I found some code here
http://www.access-programmers.co.uk/forums/showthread.php?t=118486


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
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)
'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"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If
Else
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
End If
fSetAccessWindow = (loX <> 0)
End Function

'************ Code End **********
0
Comment
Question by:DBDaveg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39838067
I have been using this code successfully for years. All forms must be popups.
0
 

Author Comment

by:DBDaveg
ID: 39838088
yes my forms ARE popup
as I said above "But both the main window AND the popup form both disappear, "
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39838107
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
errhandler:
call fSetAccessWindow(1)
msgbob err.number & vbcrlf & err.description

Open in new window

0
Independent Software Vendors: 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!

 
LVL 48

Expert Comment

by:Dale Fye
ID: 39838481
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.
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 39838584
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
0
 
LVL 10

Accepted Solution

by:
Gozreh earned 2000 total points
ID: 39838836
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.)
0
 

Author Closing Comment

by:DBDaveg
ID: 39839793
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
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question