Hide Access Window | Member | | Join Date: Mar 2007
Posts: 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?
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia
Posts: 5,429
| | | re: Hide Access Window Quote:
Originally Posted by Hutch !!!!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: - loX = apiShowWindow(Reports!rptYourReport.hWnd, nCmdShow)
| | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window
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.
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia
Posts: 5,429
| | | re: Hide Access Window Quote:
Originally Posted by Hutch 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: - Dim intHandle As Long
-
intHandle = Reports!rptYourReport.hWnd OR Me.hWnd (in proper context)
-
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)
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia
Posts: 5,429
| | | re: Hide Access Window Quote:
Originally Posted by Hutch 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 | | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window
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)"
| | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window
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.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Hide Access Window
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...
| | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window
I still need help figuring this code out
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia
Posts: 5,429
| | | re: Hide Access Window Quote:
Originally Posted by Denburt 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: - Private Sub cmdTestButton_Click()
-
Dim loX As Long
-
loX = apiShowWindow(Reports!Report1.hWnd, 0)
-
End Sub
| | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window
i dont want to hide the report, i want to have everything behind the report hidden i.e. access window.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Hide Access Window
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. -
'In the declaration section of your module.
-
Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
-
-
Function rSetAccessWindow(nCmdShow As Long, Optional myRep As Report)
-
Dim loX As Long
-
Dim intWindowHandle As Long
-
If nCmdShow = SW_SHOWMINIMIZED And myRep.Modal = True Then
-
MsgBox "Cannot minimize Access with " _
-
& (myRep.Caption + " ") _
-
& "report on screen"
-
ElseIf nCmdShow = SW_HIDE And myRep.PopUp <> True Then
-
MsgBox "Cannot hide Access with " _
-
& (myRep.Caption + " ") _
-
& "report on screen"
-
Else
-
loX = apiShowWindow(hWndAccessApp, nCmdShow)
-
End If
-
-
rSetAccessWindow = (loX <> 0)
-
intWindowHandle = myRep.hWnd
-
If Not IsZoomed(intWindowHandle) Then
-
-
DoCmd.Maximize
-
End If
-
End Function
-
Good luck
| | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window
where do i specifiy the report?
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Hide Access Window - Private Sub Report_Open(Cancel As Integer)
-
Call rSetAccessWindow(0, Me)
-
End sub
| | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window
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!!!!!!!!!!!!
| | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window
Got it to work, Really have no idea but it works!! Thanks
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Hide Access Window
Your module "SetAccessWindow"
Should look something like this" -
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
-
Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
-
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
-
Function rSetAccessWindow(nCmdShow As Long, Optional myRep As Report)
-
Dim loX As Long
-
Dim intWindowHandle As Long
-
If nCmdShow = SW_SHOWMINIMIZED And myRep.Modal = True Then
-
MsgBox "Cannot minimize Access with " _
-
& (myRep.Caption + " ") _
-
& "report on screen"
-
ElseIf nCmdShow = SW_HIDE And myRep.PopUp <> True Then
-
MsgBox "Cannot hide Access with " _
-
& (myRep.Caption + " ") _
-
& "report on screen"
-
Else
-
loX = apiShowWindow(hWndAccessApp, nCmdShow)
-
End If
-
-
rSetAccessWindow = (loX <> 0)
-
intWindowHandle = myRep.hWnd
-
If Not IsZoomed(intWindowHandle) Then
-
-
DoCmd.Maximize
-
End If
-
End Function
-
-
!!!SECOND!!! you have to paste this code into every form
-
-
Private Sub Form_Load()
-
Call fSetAccessWindow(0)
-
End Sub
-
-
In each report you need to enter the following:
-
-
Private Sub Report_Open(Cancel As Integer)
-
Call rSetAccessWindow(0, Me)
-
End sub
-
-
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia
Posts: 5,429
| | | re: Hide Access Window Quote:
Originally Posted by Hutch 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: - Public Declare Function apiShowWindow Lib "user32" _
-
Alias "ShowWindow" (ByVal hWnd As Long, _
-
ByVal nCmdShow As Long) As Long
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Hide Access Window
Glad you got it, glad we were able to help.
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia
Posts: 5,429
| | | re: Hide Access Window Quote:
Originally Posted by Denburt Glad you got it, glad we were able to help. That is why we are here, agreed?
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Hide Access Window Quote:
Originally Posted by ADezii 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.
| | Member | | Join Date: Apr 2007 Location: somewhere in your neighborhood
Posts: 52
| | | re: Hide Access Window Quote:
Originally Posted by Denburt 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.
| | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window Quote:
Originally Posted by rockdc1981 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.
| | Newbie | | Join Date: Apr 2007
Posts: 1
| | | re: Hide Access Window
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.
| | Member | | Join Date: Mar 2007
Posts: 74
| | | re: Hide Access Window Quote:
Originally Posted by Mojito05 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.
| | Newbie | | Join Date: Sep 2007
Posts: 3
| | | re: Hide Access Window
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.
| | Newbie | | Join Date: Sep 2007
Posts: 3
| | | re: Hide Access Window
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.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Hide Access Window
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 |  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Hide Access Window
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.
| | Newbie | | Join Date: Sep 2007
Posts: 3
| | | re: Hide Access Window Quote:
Originally Posted by Denburt 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?
|  | Similar Microsoft Access / VBA bytes | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 229,155 network members.
|