Define how Access opens using VBA (1 Viewer)

sstasiak

Registered User.
Local time
Today, 09:30
Joined
Feb 8, 2007
Messages
97
Hey guys

Instead of typing it over again, you can view my issue in this thread I posted in the "Forms" room:

http://www.access-programmers.co.uk/forums/showthread.php?t=125180

Is there a way to use VBA code to open Access with ONLY the default form and NOTHING else? I'm talking no toolbars, menus, NOTHING but the login form.

I'm using Access 2007 if that makes a difference.
 

modest

Registered User.
Local time
Today, 09:30
Joined
Jan 4, 2005
Messages
1,220
Search the forum for no right click. This issue has already been addressed. Additionally, search for no toolbars. You can turn off all toolbars through code when the form opens.
 

sstasiak

Registered User.
Local time
Today, 09:30
Joined
Feb 8, 2007
Messages
97
I did a search and nothing I found is working for me.

I use all the code that ghudson provides in his code listing, and it's not working.

When I try to hide menus, using his code, it only hides the "Access objects" list and disables right clicking in the forms. I need ALL menus disabled and right clicking disabled for the entire DB, meaning if I right click on the "Home" ribbon, I won't get options to edit Access Options.

I'll keep trying though.

Again, I'm using Access 2007
 

sstasiak

Registered User.
Local time
Today, 09:30
Joined
Feb 8, 2007
Messages
97
Still haven't found anything that works. With the "Home" ribbon and Office button still there, a curious user can right click either one, go into Access Options, change the startup form from the main login form to the main form, thereby negating any security I have set up through forms.

The only thing that I think would work, is if I hide the Access window altogether, and just display the forms. That way there is nothing the user can right click.

But I still don't know how to do this in 2007.

HELP!!
 

JohnInStockie

New member
Local time
Today, 14:30
Joined
Mar 20, 2007
Messages
2
Hi

I take it you dont want to hide the whole access window completely then, or do you mean that using windows to hide the acccess window doesnt work?

Im refering to the Windows API access window hide routine from the access web.


John
 

sstasiak

Registered User.
Local time
Today, 09:30
Joined
Feb 8, 2007
Messages
97
John

Right now in the "Current Database" view in "Access Options", I have the navigation pane, ribbons, menus, and shortcut menus disabled. However, when I close and re-open the DB, I still see the "Home" ribbon and the Office button on the top left corner. With those items there, the user can right click on them and select "Customize Quick Access Toolbar". Once in that customization screen, they can set the default form to be whatever they want. This totally bypasses the security I have manually built in.

I have 2 options:

1. Find out how to get rid of the "Home" ribbon and the "Office" button(or disable right clicking on them....the methods to do this that I found on here didn't work. It didn't prevent right clicking on the ribbons).

2. Make it so that the Access window doesn't actually open when the DB is opened. Meaning when I double click the icon for the DB, only the default form opens, and not the actual MS Access window.

I tried all kinds of code I found from the site and none of it works. I only saw it listed as working for Access 2003, not '07.
 

PC User

Registered User.
Local time
Today, 06:30
Joined
Jul 28, 2002
Messages
193
I have a question about using the API hide access window module. This works ok for my forms, but the report preview window always gets hidden or shows up behind the form. How can I use this module and have the preview reports in front of the form?

Thanks,
PC
 

boblarson

Smeghead
Local time
Today, 06:30
Joined
Jan 12, 2001
Messages
32,059
You have to close the form before opening the report because the forms are set to "popup" which keeps them on top.
 

PC User

Registered User.
Local time
Today, 06:30
Joined
Jul 28, 2002
Messages
193
Thanks for your reply. When I close the form for the report to appear, it works. However, when I try to get the form to return to its previous state, the API module (hide/show access window) doesn't handle the form right. Have you seen a sample of the correct handling of the API module when previewing a report and then returning to the previous form? I can't seem to get it to work.

Thanks,
PC
 

boblarson

Smeghead
Local time
Today, 06:30
Joined
Jan 12, 2001
Messages
32,059
I didn't use the API when hiding the Db window. I just made use of pop up forms and then having to close the form, maximize the db window, open the report, then in the close of the report minimizing the db window and then opening the form.
 

vbaDev

Registered User.
Local time
Today, 09:30
Joined
Feb 26, 2007
Messages
64
we need to distinguish between the Database window (that shows your tables, forms, etc. This DB window is inside the Access window).

The Access Window, is the main container form (like that of Word or Excel which contains the documents). This window has the toolbars and menus, etc.

it's possible to hide the DB window via settings.

to me knowledge it's not possible to hide the Access window without API and even that has its drawbacks/difficulties, because your forms must be modal and popup and also if you open any reports/tables, you need to have your form close (and then reopen after the report/table is closed).

Although really cool, in my experience, it's not necessarily practical, but that depends on your app.
 

boblarson

Smeghead
Local time
Today, 06:30
Joined
Jan 12, 2001
Messages
32,059
It is possible to hide the Access window without the API (it still shows in the task bar, but yes - you can hide the application window without using the API)

I didn't like all of the hassle of having to make sure that things happened in the correct order for it to work, so I just stopped doing that years ago.
 

PC User

Registered User.
Local time
Today, 06:30
Joined
Jul 28, 2002
Messages
193
That's a good point about clarifying terminology. The website "The Access Web" at http://www.mvps.org/access/api/api0019.htm uses the term "The Main Access Window." I use the code from this site to show only the active form, but is cumbersome to figure out how to effectively do a report preview and return to the previous form.

How do you do the same thing without API?

Thanks,
PC
 

boblarson

Smeghead
Local time
Today, 06:30
Joined
Jan 12, 2001
Messages
32,059
You set all of your forms as Popup, and you have to set the code to minimize the app window first, then open the form. Then, if you need to open a different form (only one can be open at a time with this method - at least that I've found), you have to close the first one and then open the second. To open a report from a form, you have to first close the form, restore the app window, open the report and then have code in the report's on close event to minimize the app window and then open the form. ...Painful process.
 

vbaDev

Registered User.
Local time
Today, 09:30
Joined
Feb 26, 2007
Messages
64
painful, but... no API! Could you please provide sample code?

I like the fact that Access could still show up in Taskbar. changing window's modality could be handled from code, could it not?

Thx!
 

boblarson

Smeghead
Local time
Today, 06:30
Joined
Jan 12, 2001
Messages
32,059
There really isn't any code to give you. It's just a matter of running the normal form opening and closing code, the report opening code, and code within the on close event of the reports. The key things to remember are:

1. When Access opens you need to minimize the app window using DoCmd.RunCommand acCmdAppMinimize and THEN open the form. So, an autoexec macro is probably the way you have to go instead of setting a startup form.

2. Make sure all forms are set to POPUP.

3. Then, whenever you need to move from form to form, you will close the first form first and then open the second (the code to close the first and open the second can be on the first form)

4. When opening a report, use
DoCmd.Close acForm, Me.Name, acSaveNo
Docmd.RunCommand acCmdAppMaximize
Docmd.Open Report "YourReportName"

5. Then in each Report's on close event, put
DoCmd.RunCommand acCmdAppMinimize
DoCmd.Open Form "YourFormNameHere"
 

vbaDev

Registered User.
Local time
Today, 09:30
Joined
Feb 26, 2007
Messages
64
Hey, thanks! It works, even if I put the docmd.RunCommand acCmdAppMinimize line into my main form's OnOpen event (you see Access for a sec, then it's minimized). And I don't even have to close my main form when a dialog box opens (a custom form opened via acDialog argument of the open form method).

So when you view the reports, Access must be visible, right? That would be the downside, of course.

But I still agree overall: it's not that practical and wouldn't impress anyone. In most companies that use Access, users are usually familiar with Access toolbars and can be trusted with many actions (and depend on them), unless your system is a complete app (which isn't always the case in this job).

Still, I had to know how to do it! Thanks!
 

PC User

Registered User.
Local time
Today, 06:30
Joined
Jul 28, 2002
Messages
193
Thanks for the discussion. I'll have to try your method for my reports. As for forms, I don't open and close them. Instead, I design my forms to swap subforms and I use multiple subforms. See this example

Thanks,
PC
 

gold007eye

Registered User.
Local time
Today, 09:30
Joined
May 11, 2005
Messages
260
I use this non-API method of hiding the database window for all my access applications. IMO it looks better and more like a program only taking up a little of your screen. The method I use it when my default form opens (Main Menu) I have the On Open Event Procedure set as:

Code:
Private Sub Form_Open(Cancel As Integer)
DoCmd.RunCommand acCmdAppMinimize
End Sub

So when the db opens it automatically hides the DB window/ access window.

@sstasiak

If you want to turn off toolbars and such programatically simply create 2 modules and put this code in it.

Module - turnon:
Code:
Option Compare Database
Option Explicit

Function toolbarson()
DoCmd.ShowToolbar "Menu Bar", A_TOOLBAR_YES

'DoCmd.ShowToolbar "Database", A_TOOLBAR_YES
'DoCmd.ShowToolbar "Relationships", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Table Design", A_TOOLBAR_NO
'DoCmd.ShowToolbar "table Datasheet", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Query Design", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Query Datasheet", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Form Design", A_TOOLBAR_YES
'DoCmd.ShowToolbar "Form View", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Filter/Sort", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Report Design", A_TOOLBAR_YES
'DoCmd.ShowToolbar "Print Preview", A_TOOLBAR_YES
DoCmd.ShowToolbar "Toolbox", A_TOOLBAR_YES
'DoCmd.ShowToolbar "Palette", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Macro", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Microsoft", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Web", A_TOOLBAR_NO
DoCmd.ShowToolbar "Formatting (Page)", A_TOOLBAR_YES
'DoCmd.ShowToolbar "Print Menu", A_TOOLBAR_YES

End Function

Module turnoff:
Code:
Option Compare Database

Function toolbarsoff()

DoCmd.ShowToolbar "Menu Bar", A_TOOLBAR_NO
DoCmd.ShowToolbar "Database", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Relationships", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Table Design", A_TOOLBAR_NO
'DoCmd.ShowToolbar "table Datasheet", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Query Design", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Query Datasheet", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Form Design", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Form View", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Filter/Sort", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Report Design", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Print Preview", A_TOOLBAR_NO
DoCmd.ShowToolbar "Toolbox", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Palette", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Macro", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Microsoft", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Web", A_TOOLBAR_NO
DoCmd.ShowToolbar "Formatting (Page)", A_TOOLBAR_NO
'DoCmd.ShowToolbar "Print Menu", A_TOOLBAR_NO

End Function

Just adjust the commented toolbars to show or not show which ever toolbars; if you create your own custom toolbars you can also set that code in here as well.

Once you have the modules set up then just create a macro called "Autoexec" (this will run automatically everytime you open the database so you won't have to worry about adding this code to a button or form)

In the Autoexec macro refer to the "turnoff" function.

RunCode
toolbarsoff ()

**When hiding the database window -
On the note of only being able to have 1 pop-up form open at a time this is not true; you also don't have to set the Modal property to "YES" if you leave Modal as "NO" and PopUp as "YES" for the form(s) then it will allow you to open more than 1 form at a time and still be able to switch focus between the different forms. What's better is that if you minimize the forms they will minimize just above the "Start" button instead of all going to the taskbar seperately.

There is a way to view reports without having to Unhide the access db window. You can set the reports PopUp property to "YES" and this will open just like the forms. I have leaned away from this because I did find the only downside is trying to get the popup report sized correctly to be able to view easily, but it is possible to do.
 

gold007eye

Registered User.
Local time
Today, 09:30
Joined
May 11, 2005
Messages
260
But I still agree overall: it's not that practical and wouldn't impress anyone. In most companies that use Access, users are usually familiar with Access toolbars and can be trusted with many actions (and depend on them), unless your system is a complete app (which isn't always the case in this job).

I have learned in my company that the less you let the user do the better off you are. Lot's of people her like to "see how things work". So needless to say I have created my own security/design features to prevent these users from being able to do so (without using MsAcess Security which is a nightmare) The databases all look like applications and the user can only see and go where I let them or they have the access level to get to based on their network ID. It's amazing what you can do. You might also want to consider disabling the "SHIFT" function. (Holding shift while opening the database will bring up the database showing the DB Window where the user can see/modify,etc forms, table, etc.) If you need any code for that let me know. It is definetly a good feature to implement.
 

Users who are viewing this thread

Top Bottom