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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent users closing application with X i.e must use switchboard 5

Status
Not open for further replies.

mwheads

Programmer
Apr 24, 2004
38
0
0
ZA
Hi Everyone

Is there a way with options (disable X) or VBA of preventing users from closing the application with the X. I want my users to only use the switchboard to enter and exit the database.

thanks

Paul
 
Also the custom caption showing [formname:form] only seems to happen when I maximize my window. If I leave out this line, I don't have the problem but then my form is not in the very left top corner of the window. :(

Code:
DoCmd.Maximize
 
Very weird problem now.
I removed the code to set a custom caption and hide the minimize/maximize/close buttons from my Form_Load(). Minimize/maximize/close buttons are back again, but the caption still says something else then Microsoft Access.
Also I added your icon code, but it just shows the default access icon, not my own.

Here's my entire Form_Load() code. Let me know when you wanna see any of the modules.

Code:
Private Sub Form_Load()
On Error GoTo Err_Form_Load


    'Dim lLng_HideAccessWord    As Long
    Dim lBol_SetIcon As Boolean
   
    'fLng_OrigWindWord = GetWindowLong(hWndAccessApp, GWL_STYLE)
    'lLng_HideAccessWord = fLng_OrigWindWord And (Not WS_SYSMENU)
    'SetWindowLong hWndAccessApp, GWL_STYLE, lLng_HideAccessWord
    'RedrawTitleBar "Blablabla"
    
    lBol_SetIcon = WindowSetIcon(Me.hWnd, "C:\myicon.ico")

    Call ResizeAppWindow
    DoCmd.Maximize

Exit_Form_Load:
    Exit Sub
    
Err_Form_Load:
    MsgBox Err.Description
    Resume Exit_Form_Load
End Sub
 
Are we talking about the Form's window, or the main Access window?
What does the ResizeAppWindow function do?
Have you tried setting the icon after the DoCmd.Maximize?



--------------
Good Luck
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
It's the main Access window. When I use your code I manage to change the "Microsoft Access" caption into something else, but the access icon dissappears.
The code for replacing this icon does not seem to do much. Not even when I do not change the caption, it just shows the default Access icon.

Also the [formname:form] thing in the caption only appears after a maximize, because when you maximize a form it does not have it's own titlebar anymore, so it puts the formname in the main Access window titlebar like this.

What I try to do is hide the form's titlebar and window, maximize my form (so the main Access titlebar becomes my form's titlebar) and then change the standard Access icon and caption and hide the minimize/maximize/close button.
But maybe I have to do it the other way around. Perhaps I could just hide the main Access window completely (so my form's titlebar is the only one showing), disable minimize/maximize/close button on my form, and then change the icon and caption for the form window ? Don't know if it's possible.

The ResizeAppWindow function just resizes my Access window to a set value.
 
Since we're talking about the main access window, we need to ensure that we're using that window handle, and not the form's window handle.

In the following line of code:[tt]
lBol_SetIcon = WindowSetIcon(Me.hWnd, "C:\myicon.ico")[/tt]
The Me.hWnd identifies which window is to get that icon. Me.hWnd identifies the form's window. If you want to work with the main Access window, then you need to use that window's handle. This is true for the icon, caption, and any window manipulation routine.

Try replacing the Me.hWnd with hWndAccessApp which will tell the function to work with the main Access window instead of the form's window.

--------------
Good Luck
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
This works as long as I do not use the code for hiding minimize/maximize/close buttons and adding custom caption. When I do use that code, there is no icon.

However, for some strange reason my caption now remains the custom title I set before, I doesn't turn back to "Microsoft Access", even if I comment out the code for changing the caption.
 
You may need to programatically tell Microsoft Access to put the caption back to what it should be when you close the database...?

This is because you change a setting, it keeps that setting until you tell it otherwise.

Just a suggestion...

Aubs
 
Aubs010 is correct. You should reset the main access window attributes back to their defaults. One place where that may be done is the last Form_Unload event.

--------------
Good Luck
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thx, it's back to normal now.
But I still can't get both the code for hiding the X button and the code for a custom icon to work at the same time. The code for hiding the X button also seems to hide my icon. :(
 
Is it that you have got it to disable the icon - Don't forget, in most windows programs, where the logo is at the top left of the window, there is a CLOSE option within the menu that pops down...

Try hitting ALT+Space and see if it brings up the application's menu (try it in Word/Explorer/any other app for an example)

It if doesn't bring up a menu, then something in some code MUST be hiding it!



Aubs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top