hiding access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone help me? I would like to know how to hide Access and show the main
form only. I have seen a post refering to this previously but typically, I
can't seem to find it now!

Thankyou in advance.

Me.
 
I'm really sorry for my ignorance but I can't seem to insert the code using
the "Open Event" property on the form. Do I need to manipulate the code? I
know it may be too much trouble to explain where I'm going wrong so please
don't feel obliged to answer. I am very
new to VB and fear I may be in over my head!
 
I just recently needed to be able to hide the Access window in a quickie
access app. The app had just one form which was used to log events an keep
track of time during the day. The customer wanted the form to always be
visible an positioned to the upper right hand corner of the screen. They
wanted the from to be as small as possible, and did not want any other
windows to be visible.

What I would up doing was to make my one and only form an Access popup from.
It is also the Access start up form. So when Access starts my form loads.
My form calls a sub that moves it to the upper right hand corner and then
moves and resizes the Access MDI window to the same coordinates, directly
underneath my form. End result is it appears that the Access MDI window has
disappeared.

Here is the function that does the deed:


Public Sub UpperLeftPopupUp(f As Form)
' Purpose Puts the Form f in the Extreme Top Right of the screen if it is
an
' Access Popup form. Populates the PMDIRect Rect Structure with
the inital
' placement of the Access MDI window before it moves it under the
Popup form f.
Dim FrmRect As RECT
Dim RetVal As Long

If f.PopUp = False Then
Exit Sub
End If

' If the form is maximized, restore it.
If IsZoomed(f.hWnd) <> 0 Then
RetVal = ShowWindow(f.hWnd, SW_SHOWNORMAL)
End If
' Get the screen coordinates and window size of the MDIClient window.
RetVal = GetWindowRect(GetParent(f.hWnd), PMDIRect)
RetVal = GetWindowRect(f.hWnd, FrmRect)
' Move the form to the UpperRight Corner of the Screen
RetVal = MoveWindow(f.hWnd, _
(GetSystemMetrics(SM_CXFULLSCREEN) - (FrmRect.Right -
FrmRect.Left)), _
(0), _
FrmRect.Right - FrmRect.Left, _
FrmRect.Bottom - FrmRect.Top, _
True)
' Move Access Directly underneath out popup form (Access appears to be
minimized)
RetVal = MoveWindow(hWndAccessApp, _
(GetSystemMetrics(SM_CXFULLSCREEN) - (FrmRect.Right -
FrmRect.Left)), _
(0), _
FrmRect.Right - FrmRect.Left, _
FrmRect.Bottom - FrmRect.Top, _
True)
End Sub


You will need the following Declares in the same module.


Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, _
lpRect As RECT) As Long
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long
Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, _
ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As
Long

' Show Window Constants
Const SW_MAXIMIZE = 3
Const SW_SHOWNORMAL = 1

' System Metrics Constant
Const SM_CYCAPTION = 4
Const SM_CXFULLSCREEN = 16
Const SM_CYFULLSCREEN = 17

The only "problem" I had with this setup was if I called Call
UpperLeftPopupUp(me) from the form load event occasionally I would crash
Access. What I wound up doing was setting the timer to 100ms and calling
the code from the OnTimer event thusly:

Private Sub Form_Timer()
If Me.TimerInterval <= 110 Then
' Runs this code one time only just to position the form
' in the upper Left Hand Corner of the screen at Start Up
Me.TimerInterval = 0
Call UpperLeftPopupUp(Me)
End If
End Sub

Apparently Access is not done doing at it has to do by the time the start up
form was loading. Waiting a tenth of a second after form load allows enough
time for Access to get itself stabilized.

Sooo.... By all means use the link that Brian provided if it makes sense,
but here is another possible way to get the deed done if you have at least
one form you want to have displayed.

Ron W
 
Sorry to pester you again. After a bit of messing around I have managed to
put the code in the correct place & instructed the event procedure OnOpen to
call the function. However the error msg appears "Cannot hide access unless
form is on screen" as per the code. Sadly I don't understand the code well
enough to isolate the specific cause. Any ideas?
 
JohnC said:
Sorry to pester you again. After a bit of messing around I have
managed to put the code in the correct place & instructed the event
procedure OnOpen to call the function. However the error msg appears
"Cannot hide access unless form is on screen" as per the code. Sadly
I don't understand the code well enough to isolate the specific
cause. Any ideas?

The form must have both its Modal and PopUp properties set to Yes.
 
The same message is still appearing. The code is as follows:

Function fSetAccessWindow(SW_HIDE)
'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

Does anything stand out? I appreciate your time.
 
JohnC said:
The same message is still appearing. The code is as follows:

Function fSetAccessWindow(SW_HIDE)
'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

Does anything stand out? I appreciate your time.

You're calling the function fSetAccessWindow from an event procedure for
the Open event of the form you want to leave on the screen? Before you
call the function in the form's Open event, insert the statement

Me.Visible = True

and see if that fixes it.
 
You wont believe this! Now it claims that it can't hide access whilst my form
is on screen!! Before it couldn't hide access because there was no screen.
I've tried changing the Modal and Popup properties in every combination????
Sorry for the inconvenience.
 
JohnC said:
You wont believe this! Now it claims that it can't hide access whilst
my form is on screen!! Before it couldn't hide access because there
was no screen. I've tried changing the Modal and Popup properties in
every combination???? Sorry for the inconvenience.

What version of Access? In Access 97 I had to use the Timer event to make
this work as Open and Load both produced the error you're seeing.
 
Hello Rick, I'm using Access 2000. If I set both Modal and Popup to Yes then
everything disappears (including the form)!!! If either one is set to No then
the message appears. I didn't realise this would be such a pain!
 
JohnC said:
You wont believe this! Now it claims that it can't hide access whilst
my form is on screen!! Before it couldn't hide access because there
was no screen. I've tried changing the Modal and Popup properties in
every combination???? Sorry for the inconvenience.

I think that message must mean that the form's PopUp property is not set
to Yes. Is it possible you messed that up while you were thrashing
about trying to get this to run?

I just looked into a form that I set up in my "test" database to try out
this code. That form works just fine at hiding the Access window. It
has its PopUp and Modal properties both set to Yes, and it has this code
for its Open and Close events:

'----- start of code -----
Private Sub Form_Close()
fSetAccessWindow SW_SHOWNORMAL
End Sub

Private Sub Form_Open(Cancel As Integer)
Me.Visible = True
DoEvents
fSetAccessWindow SW_HIDE
End Sub
'----- end of code -----

I notice that I have one more line in the Open event than I told you
about before: DoEvents. Try putting that in, to let the form become
visible before attempting to hide the Access window.
 
Dirk you are a life saver. It finally works!!! Thank you so much for your
patience & time. There is just one tiny little issue I have left. I'll
understand completely if you tell me to get lost as I've already taken up far
too much of your time. But in case you feeling charitable I'll mention my new
little problem.

Access is now hidden & my beautiful form is standing prominent. On my form
there are a few buttons. One of these buttons runs a report preview OnClick.
Which, as you've probably guessed remains hidden with access. Any ideas? I
know I'm very needy & I do apologise but your time & wisdom is very much
appreciated.
 
JohnC said:
Dirk you are a life saver. It finally works!!! Thank you so much for
your patience & time. There is just one tiny little issue I have
left. I'll understand completely if you tell me to get lost as I've
already taken up far too much of your time. But in case you feeling
charitable I'll mention my new little problem.

Access is now hidden & my beautiful form is standing prominent. On my
form there are a few buttons. One of these buttons runs a report
preview OnClick. Which, as you've probably guessed remains hidden
with access. Any ideas? I know I'm very needy & I do apologise but
your time & wisdom is very much appreciated.

You've just exceeded the usefulness of the "Hide access" technique. It is
really only suitable for simple "One form at a time" apps and many things
(like previewing reports) are just not practical.
 
Hello Rick, I'm half way there. I've used the following code to make the
report preview visible:

Private Sub PhoneBook_Click()
On Error GoTo Err_PhoneBook_Click

Dim stDocName As String

stDocName = "HaulierPhoneBook"
DoCmd.OpenReport stDocName, acPreview
fSetAccessWindow SW_SHOWMAXIMIZED
Form.Modal = False
Me.Visible = False

Exit_PhoneBook_Click:

Exit Sub

Err_PhoneBook_Click:
MsgBox Err.Description
Resume Exit_PhoneBook_Click

End Sub

If I could just revert the Form.Modal & the Me.Visible when the preview is
closed I would be a very happy man!
 
JohnC said:
Hello Rick, I'm half way there. I've used the following code to make
the report preview visible:

Private Sub PhoneBook_Click()
On Error GoTo Err_PhoneBook_Click

Dim stDocName As String

stDocName = "HaulierPhoneBook"
DoCmd.OpenReport stDocName, acPreview
fSetAccessWindow SW_SHOWMAXIMIZED
Form.Modal = False
Me.Visible = False

Exit_PhoneBook_Click:

Exit Sub

Err_PhoneBook_Click:
MsgBox Err.Description
Resume Exit_PhoneBook_Click

End Sub

If I could just revert the Form.Modal & the Me.Visible when the
preview is closed I would be a very happy man!

I don't know if you're accomplishing anything useful with
Form.Modal = False

-- I expect setting the form's Visible property is doing the job. To
restore the form and hide the Access window again when the report
preview closes, how about code in the report's Close event?

'----- start of untested code -----
Private Sub Report_Close()

If CurrentProject.AllForms("YourFormName").IsLoaded Then
Forms("YourFormName").Visible = True
DoEvents
fSetAccessWindow SW_HIDE
End If

End Sub

'----- end of code -----
 
That's done it! You were right about Modal = False. Thank you very, very much
for your time. I really do appreciate your help. Sorry for all the trouble.

Bye for now.
 
Back
Top