By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,666 Members | 1,603 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,666 IT Pros & Developers. It's quick & easy.

Hide Access Window

P: 74
!!!!FIRST!!! The fallowing code gets placed into a module that has to be called "SetAccessWindow"

Option Compare Database
Option Explicit

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)

Dim loX As Long
Dim loform As Form
On Error Resume Next
Set loform = Screen.ActiveForm

If Err <> 0 Then
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If

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
fSetAccessWindow = (loX <> 0)
End Function


!!!SECOND!!! you have to paste this code into every form

Private Sub Form_Load()
Call fSetAccessWindow(0)
End Sub



The above code works great on forms, but i cant get it to function on Reports. Help?
Apr 6 '07 #1
Share this Question
Share on Google+
29 Replies


ADezii
Expert 5K+
P: 8,652
!!!!FIRST!!! The fallowing code gets placed into a module that has to be called "SetAccessWindow"

Option Compare Database
Option Explicit

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)

Dim loX As Long
Dim loform As Form
On Error Resume Next
Set loform = Screen.ActiveForm

If Err <> 0 Then
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If

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
fSetAccessWindow = (loX <> 0)
End Function


!!!SECOND!!! you have to paste this code into every form

Private Sub Form_Load()
Call fSetAccessWindow(0)
End Sub



The above code works great on forms, but i cant get it to function on Reports. Help?
The 'Handle' to a Report Window is defined by its hWnd Property. Are you properly passing this value to the API Function, something similar to:
Expand|Select|Wrap|Line Numbers
  1. loX = apiShowWindow(Reports!rptYourReport.hWnd, nCmdShow)
Apr 7 '07 #2

P: 74
loX = apiShowWindow(Reports!rptYourReport.hWnd, nCmdShow)

I tried pasting the above in the code were i saw it begin with "lox=" but no success. do i need to write this code for every report i have a place the report name in "rptYourReport"?

I use this code just the way you see it at the top of this page and it works on all my forms just fine, could it have something to do with the "form" verbage used through out the code? i tried changing this to "report" and still had no luck.
Apr 7 '07 #3

ADezii
Expert 5K+
P: 8,652
loX = apiShowWindow(Reports!rptYourReport.hWnd, nCmdShow)

I tried pasting the above in the code were i saw it begin with "lox=" but no success. do i need to write this code for every report i have a place the report name in "rptYourReport"?

I use this code just the way you see it at the top of this page and it works on all my forms just fine, could it have something to do with the "form" verbage used through out the code? i tried changing this to "report" and still had no luck.
__1. The Reports must be Open for the code to work.
__2. You need only pass the 'Handle' of the open Report to the API Function:
Expand|Select|Wrap|Line Numbers
  1. Dim intHandle As Long
  2. intHandle = Reports!rptYourReport.hWnd OR Me.hWnd (in proper context)
  3. loX = apiShowWindow(intHandle, nCmdShow)
__3. As far as apiShowWindow() is concerned, it only needs a Long Integer representing the Handle of the Report and a Parameter indicating what it should do with this Window (Report)
Apr 7 '07 #4

ADezii
Expert 5K+
P: 8,652
loX = apiShowWindow(Reports!rptYourReport.hWnd, nCmdShow)

I tried pasting the above in the code were i saw it begin with "lox=" but no success. do i need to write this code for every report i have a place the report name in "rptYourReport"?

I use this code just the way you see it at the top of this page and it works on all my forms just fine, could it have something to do with the "form" verbage used through out the code? i tried changing this to "report" and still had no luck.
I have made the assumption that you have modified the following lines of code to reference a Report and not a Form, have you?

Function fSetAccessWindow(nCmdShow As Long)
Set loform = Screen.ActiveForm

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
End If
End Function
Apr 7 '07 #5

P: 74
Yes i changed all the verbage of "Form" to "Report" Example

Dim loX As Long
Dim loform As Form
On Error Resume Next
Set loform = Screen.ActiveForm

is now

Dim loX As Long
Dim loform As Report
On Error Resume Next
Set loform = Screen.ActiveReport

but i cant seem to find the following code to change that you call out in your last reply

"Dim intHandle As Long
intHandle = Reports!rptYourReport.hWnd OR Me.hWnd (in proper context)
loX = apiShowWindow(intHandle, nCmdShow)"
Apr 9 '07 #6

P: 74
After all these changes the code does not work on the reports but still works on the forms. argh!


Thank you so much for all your help.
Apr 9 '07 #7

Denburt
Expert 100+
P: 1,356
Interesting approach, I was also able to utilize it for my forms but not the reports, it must have something to do with the fact that reports are handled differently...
Apr 9 '07 #8

P: 74
I still need help figuring this code out
Apr 9 '07 #9

ADezii
Expert 5K+
P: 8,652
Interesting approach, I was also able to utilize it for my forms but not the reports, it must have something to do with the fact that reports are handled differently...
Denburt, just for your own information:
I had absolutely no problem opening a Report called Report1, then executing the following code in the Click() Event of a Command Button. The end result was that that Report1 was now hidden. I did call the API Function directly:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdTestButton_Click()
  2.   Dim loX As Long
  3.   loX = apiShowWindow(Reports!Report1.hWnd, 0)
  4. End Sub
Apr 9 '07 #10

P: 74
i dont want to hide the report, i want to have everything behind the report hidden i.e. access window.
Apr 9 '07 #11

Denburt
Expert 100+
P: 1,356
I could be mistaken but from what I think you want you are trying to hide the MS Access application but still show reports forms etc. correct?

If this is so then you left out a couple of key pieces of info that would help us understand... Your forms are set to popup and Modal correct?

Using the on_load event allows the following to work...

screen.activeform

However since a report does not have an onload event you need to specify which report you are using. I also modified it a bit by grabbing the hwnd of the report itself.


Expand|Select|Wrap|Line Numbers
  1. 'In the declaration section of your module.
  2. Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
  3.  
  4. Function rSetAccessWindow(nCmdShow As Long, Optional myRep As Report)
  5. Dim loX As Long
  6.  Dim intWindowHandle As Long
  7. If nCmdShow = SW_SHOWMINIMIZED And myRep.Modal = True Then
  8.     MsgBox "Cannot minimize Access with " _
  9.     & (myRep.Caption + " ") _
  10.     & "report on screen"
  11. ElseIf nCmdShow = SW_HIDE And myRep.PopUp <> True Then
  12.     MsgBox "Cannot hide Access with " _
  13.     & (myRep.Caption + " ") _
  14.     & "report on screen"
  15. Else
  16.     loX = apiShowWindow(hWndAccessApp, nCmdShow)
  17. End If
  18.  
  19. rSetAccessWindow = (loX <> 0)
  20.     intWindowHandle = myRep.hWnd
  21.     If Not IsZoomed(intWindowHandle) Then
  22.  
  23. DoCmd.Maximize
  24.     End If
  25. End Function
  26.  
Good luck
Apr 9 '07 #12

P: 74
where do i specifiy the report?
Apr 9 '07 #13

Denburt
Expert 100+
P: 1,356
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2. Call rSetAccessWindow(0, Me)
  3. End sub
Apr 9 '07 #14

P: 74
loX = apiShowWindow(hWndAccessApp, nCmdShow)

i got an error that tells me the above code is incorrect, that the sub or fuction is not defined help!!!!!!!!!!!!
Apr 9 '07 #15

P: 74
Got it to work, Really have no idea but it works!! Thanks
Apr 9 '07 #16

Denburt
Expert 100+
P: 1,356
Your module "SetAccessWindow"

Should look something like this"
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Global Const SW_HIDE = 0
  5. Global Const SW_SHOWNORMAL = 1
  6. Global Const SW_SHOWMINIMIZED = 2
  7. Global Const SW_SHOWMAXIMIZED = 3
  8. Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
  9. Private Declare Function apiShowWindow Lib "user32" _
  10. Alias "ShowWindow" (ByVal hWnd As Long, _
  11. ByVal nCmdShow As Long) As Long
  12. Function fSetAccessWindow(nCmdShow As Long)
  13.  
  14. Dim loX As Long
  15. Dim loform As Form
  16. On Error Resume Next
  17. Set loform = Screen.ActiveForm
  18.  
  19. If Err <> 0 Then
  20. loX = apiShowWindow(hWndAccessApp, nCmdShow)
  21. Err.Clear
  22. End If
  23.  
  24. If nCmdShow = SW_SHOWMINIMIZED And loform.Modal = True Then
  25. MsgBox "Cannot minimize Access with " _
  26. & (loform.Caption + " ") _
  27. & "form on screen"
  28. ElseIf nCmdShow = SW_HIDE And loform.PopUp <> True Then
  29. MsgBox "Cannot hide Access with " _
  30. & (loform.Caption + " ") _
  31. & "form on screen"
  32. Else
  33. loX = apiShowWindow(hWndAccessApp, nCmdShow)
  34. End If
  35. fSetAccessWindow = (loX <> 0)
  36. End Function
  37. Function rSetAccessWindow(nCmdShow As Long, Optional myRep As Report)
  38. Dim loX As Long
  39.  Dim intWindowHandle As Long
  40. If nCmdShow = SW_SHOWMINIMIZED And myRep.Modal = True Then
  41.     MsgBox "Cannot minimize Access with " _
  42.     & (myRep.Caption + " ") _
  43.     & "report on screen"
  44. ElseIf nCmdShow = SW_HIDE And myRep.PopUp <> True Then
  45.     MsgBox "Cannot hide Access with " _
  46.     & (myRep.Caption + " ") _
  47.     & "report on screen"
  48. Else
  49.     loX = apiShowWindow(hWndAccessApp, nCmdShow)
  50. End If
  51.  
  52. rSetAccessWindow = (loX <> 0)
  53.     intWindowHandle = myRep.hWnd
  54.     If Not IsZoomed(intWindowHandle) Then
  55.  
  56. DoCmd.Maximize
  57.     End If
  58. End Function
  59.  
  60. !!!SECOND!!! you have to paste this code into every form
  61.  
  62. Private Sub Form_Load()
  63. Call fSetAccessWindow(0)
  64. End Sub
  65.  
  66. In each report you need to enter the following:
  67.  
  68. Private Sub Report_Open(Cancel As Integer)
  69. Call rSetAccessWindow(0, Me)
  70. End sub
  71.  
  72.  
Apr 9 '07 #17

ADezii
Expert 5K+
P: 8,652
loX = apiShowWindow(hWndAccessApp, nCmdShow)

i got an error that tells me the above code is incorrect, that the sub or fuction is not defined help!!!!!!!!!!!!
You are getting this Error because your API is declared Privately as opposed to Publically. Declare it as:
Expand|Select|Wrap|Line Numbers
  1. Public Declare Function apiShowWindow Lib "user32" _
  2. Alias "ShowWindow" (ByVal hWnd As Long, _
  3. ByVal nCmdShow As Long) As Long
Apr 9 '07 #18

Denburt
Expert 100+
P: 1,356
Glad you got it, glad we were able to help.
Apr 10 '07 #19

ADezii
Expert 5K+
P: 8,652
Glad you got it, glad we were able to help.
That is why we are here, agreed?
Apr 10 '07 #20

Denburt
Expert 100+
P: 1,356
That is why we are here, agreed?
Positively absolutely, I love what I do and enjoy sharing the info, hopefully someone can learn from the knowledge I have obtained. I know that it sure helps me and I learn as well.
Apr 10 '07 #21

P: 51
Positively absolutely, I love what I do and enjoy sharing the info, hopefully someone can learn from the knowledge I have obtained. I know that it sure helps me and I learn as well.

you guys are great, i was able to use the code on my welcome screen, but it takes sometime to load the form.
Apr 16 '07 #22

P: 74
you guys are great, i was able to use the code on my welcome screen, but it takes sometime to load the form.

Currently i have four individuals with a fifth who sometimes runs the program. And it takes a second or so once three users are already on it but once the users are on thier forms and entering data there is no lag time.
Apr 17 '07 #23

P: 1
I'm using this on a couple of forms in A2002 and it's working great. Although, there's 1 more thing I'd like to do, that I can't figure out.

Like some other people who are using this code, I'm trying to make my database as airtight as possible to keep users from getting into things - accidentally or intentionally.

For reference, here are some of the properties from the main form:

Pop Up: Yes
Modal: Yes
Border Style: Yes
Control Box: No
On Open: [Event Procedure]
Private Sub Form_Open(Cancel As Integer)
Me.TimerInterval = 1
End Sub
On Timer: [Event Procedure]
Private Sub Form_Timer()
Me.TimerInterval = 0
fSetAccessWindow (SW_HIDE)
End Sub
I also un-checked all of the check boxes in the database's Startup options menu. I then added a button to the form so that the user can close the database, and another button so that the form can minimized. I made the minimize button so that when it was used, something would show-up on the taskbar and not on the desktop (above the Start button). I figured the users would get confused when they had multiple windows open and couldn't find the database on the taskbar. Here's the code I put in the minimize button's On Click event:
Private Sub Image37_Click()
Dim stDocName As String
Dim stLinkCriteria As String

Me.Form.Modal = False
stDocName = "MinimizeForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
fSetAccessWindow (SW_SHOWMINIMIZED)

Exit_Image37_Click:
Exit Sub

Err_Image37_Click:
MsgBox Err.Description
Resume Exit_Image37_Click

End Sub
But once the form is minimized (I realize that it's really the main database window that's minimized, because that's what's shown on the taskbar), is there a way to maximize/re-open the form (just like it is when it's initially opened) without the main database showing-up? I tried, but I couldn't figure out a way to use SetAccessWindow (SW_HIDE) again.

So anyway, sorry for the long explanation, but just let me know if anyone has any questions or ideas.

Thanks.
Apr 24 '07 #24

P: 74
I'm using this on a couple of forms in A2002 and it's working great. Although, there's 1 more thing I'd like to do, that I can't figure out.

Like some other people who are using this code, I'm trying to make my database as airtight as possible to keep users from getting into things - accidentally or intentionally.

For reference, here are some of the properties from the main form:

Pop Up: Yes
Modal: Yes
Border Style: Yes
Control Box: No
On Open: [Event Procedure]
Private Sub Form_Open(Cancel As Integer)
Me.TimerInterval = 1
End Sub
On Timer: [Event Procedure]
Private Sub Form_Timer()
Me.TimerInterval = 0
fSetAccessWindow (SW_HIDE)
End Sub
I also un-checked all of the check boxes in the database's Startup options menu. I then added a button to the form so that the user can close the database, and another button so that the form can minimized. I made the minimize button so that when it was used, something would show-up on the taskbar and not on the desktop (above the Start button). I figured the users would get confused when they had multiple windows open and couldn't find the database on the taskbar. Here's the code I put in the minimize button's On Click event:
Private Sub Image37_Click()
Dim stDocName As String
Dim stLinkCriteria As String

Me.Form.Modal = False
stDocName = "MinimizeForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
fSetAccessWindow (SW_SHOWMINIMIZED)

Exit_Image37_Click:
Exit Sub

Err_Image37_Click:
MsgBox Err.Description
Resume Exit_Image37_Click

End Sub
But once the form is minimized (I realize that it's really the main database window that's minimized, because that's what's shown on the taskbar), is there a way to maximize/re-open the form (just like it is when it's initially opened) without the main database showing-up? I tried, but I couldn't figure out a way to use SetAccessWindow (SW_HIDE) again.

So anyway, sorry for the long explanation, but just let me know if anyone has any questions or ideas.

Thanks.

This is a very good question and something i'm very interested in, however since this conversation is based on hidding the access window and doesnt focus on your question exactly i'm reposting it back in the forum so people will see it and answer your question.
May 1 '07 #25

P: 3
As a complete newy,
where would i paste the below code, as i have tryed and cant get it to work,

Private Sub Form_Load()
Call fSetAccessWindow(0)
End Sub
Please help i have been trying for hours.
Sep 27 '07 #26

P: 3
OK now i am in trouble,
this works great as i got it to work. Know i cant work out how to get it back so i can work on the database???

Big help required.
Sep 27 '07 #27

Denburt
Expert 100+
P: 1,356
This question was followed up in the following thread:
http://www.thescripts.com/forum/thread640403.html

I found a resolution utilizing the following article. Just check to see if the MS Access application is in the state you want. If it isn't then change the app state. This link utilizes some of the functions/code from earlier in this thread so don't confuse yourself by just doing a copy and paste since you would likely end up declaring the same function twice.

http://support.microsoft.com/kb/210118
Sep 27 '07 #28

Denburt
Expert 100+
P: 1,356
FYI if you just want to view the Main database window for some temp maintenance you should be able to just hold the shift key down when starting the app and bypass the main startup form, unless of course you have this feature disabled, in which case you might need to call it from another app (I had to once) to re enable this feature.
Sep 27 '07 #29

P: 3
FYI if you just want to view the Main database window for some temp maintenance you should be able to just hold the shift key down when starting the app and bypass the main startup form, unless of course you have this feature disabled, in which case you might need to call it from another app (I had to once) to re enable this feature.
I am not sure weather you get me,
I have used the code above to close the application window, i have tryed shift key, how do i call it from another app?
Sep 28 '07 #30

Post your reply

Sign in to post your reply or Sign up for a free account.