Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running Form in a window independent of Microsoft Access 7

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
0
0
US
I was wondering if there was a way to cause a database which was built in Access to run in a separate window outside of Access when the end-user is running the database (using forms/reports, etc).
 
The only way to do what you are looking to do is hide the access window. Put this code into a module:
Code:
Option Explicit

Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Dim dwReturn As Long

Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
     ByVal nCmdShow As Long) As Long
     
Public Function fAccessWindow(Optional Procedure As String, Optional SwitchStatus As Boolean, Optional StatusCheck As Boolean) As Boolean
If Procedure = "Hide" Then
    dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
End If
If Procedure = "Show" Then
    dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
End If
If Procedure = "Minimize" Then
    dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMINIMIZED)
End If
If SwitchStatus = True Then
    If IsWindowVisible(hWndAccessApp) = 1 Then
        dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
    Else
        dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
    End If
End If
If StatusCheck = True Then
    If IsWindowVisible(hWndAccessApp) = 0 Then
        fAccessWindow = False
    End If
    If IsWindowVisible(hWndAccessApp) = 1 Then
        fAccessWindow = True
    End If
End If
End Function

Then to use this code make sure your form is set to pop up and on form load put this code:
Code:
fAccessWindow "Minimize", False, False

That should do the trick for you

HTH
Mike

[noevil]
 
Thanks a bunch. That looks like it will work, will report back if any problems (and if I remember to if no problems.) By the way, is this type of coding bypassed if I open the database with Shift held down

That code will be very useful I think.
 
Thanks for the code and info! It does the task very well. Now, I just have to make sure that when someone closes the form, it closes Access as well, but I think I can do that by hiding the X or "close" button on the top right of the form. Is there are particular part of code I could change in the module to do that?
 
Just a followup on this one: I simply set up a button on the main form with the control wizard which states "exit database" and by doing this, it closes the database, Access and all. I used the control wizard, and chose the option, "exit application" - duh..



Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
mgolla - Can you, using this particular approach, have multiple windows being shown, and not modal so as to retain the MDI functionality? Also, with this approach, will your windows show up in the Taskbar?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Well, all the windows do not show in the taskbar, but I can have them show up independantly. They way my database is now set up, when I go away from the "intro" form, I set its visible property to false, thus hiding it from view while the appropriate form for a given task is showing. Then when on the other form, I hit a button that says "return to main", The second/other form closes, and the "intro" form visible property is set to true. The only window that shows up in my taskbar is the one that says "Microsoft Access" - currently.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
In other words, you cannot have two windows open at the same time, allowing the user to switch back and forth between them? So by using this approach, (which by the way, is not the only way to hide the Access window), you give up MDI functionality?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Um, not sure - MDI functionality - is that the ability to swtich between forms/windows? If so - I just have buttons to take care of that. What other ways do you know of to hide the access window while in an Access database?

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Transparent Regions.

One of the primary advantages of a MDI is that you can have two windows open, side by side, so that the user can see both windows, and can move between by simply clicking on the title bar. You can also switch between the windows by clicking on them in the title bar. Suppose that your window is covered up by a full screen app, like Internet Explorer, how can you then get back to either of your two Access Application windows?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Can't the user just "ALT-TAB" over to the Access Window? Well, I think that it would not be necessary for this particular database, but I may find at some point, that some actions would necessitate that method. Could you explain a little about the Transparent Regions, or point me to a good location to learn about that? I would be most appreciative.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
To get you started, take a look at the following thread:

thread702-702093

This uses regions to make a form background transparent. Using this same general idea, you can do the same to the Access window, but you will have to subclass windows and it does get somewhat more complicated as you have to deal with other issues as well. But this thread would be a good starting point to get familiar with regions and transparency.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Just so you don't get the wrong impression, using the ShowWindow API to hide access is fine, in some limited cases. But if in your application you need to view a report on the screen, or as I said earlier, need MDI capabilities, or need modeless windows, you'll run into some difficulties.

The approach outlined by mgolla is valid and simple, but you also need to be aware of the cost of that simplicity, both in terms of lost functionality, and increased user-interface complexity, especially with inter-window navigation.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks a bunch. I'll definitely look into it. I can definitely see where it might be necessary for when viewing reports - as that will be one of the tools necessary in this.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Well I glanced over the thread you mentioned, and I think I'll wait a little while before trying that - will take care of other things first. It is an interesting idea, but I think I'll first try to work around it with the use of buttons and such. If I can't, then I may try to go that route. Thanks for the info.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Was wondering if anyone was experiencing the problem I am having when using this code. If i go to preview a report I cannot print it, cannot right click and get the shortcut menus to come up from anywhere.....has anyone else had this problem....any suggestions on how to fix it? I tried creating a custom shortcut menu but that still does not work....

any help or suggestions are appreciated!

thanks

Paul
 
I think Cajun already kind of answered that to some extent, Paul. Take a look at the link he mentioned for a fix.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Fantastic code Mgolla. I have an access database used by supervisors that just has 1 form for monitoring. This code makes it simple enough that its almost impossible for them to do something wrong :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top