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
Solved

hide access window, dislay popup form

Posted on 2014-02-05
7
6,953 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
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.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

809 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