Solved

hide access window, dislay popup form

Posted on 2014-02-05
7
6,815 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
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
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 500 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

810 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