Solved

hide access window, dislay popup form

Posted on 2014-02-05
7
6,519 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 26

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 26

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now