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!

Close temporary form without a dialog box

Status
Not open for further replies.

dkellygb

IS-IT--Management
Aug 28, 2001
18
0
0
GB
Hello,

I am creating a temporary form programmatically with a large number of controls to interact with the user. I do not need to save the form when the user exits the application or if he decides to close the form. However, when I try to docmd.setwarnings false in the unload event, the form still asks me for a name for my form. If I don't set docmd.setwarnings false, I get the dialog box which asks me whether I want to save or not.

My question is, how can I prevent the user from seeing the close dialog box if he closes the form or the application?

Thanks,

Dave
 
Have you tried using the third parameter of the DoCmd.Close statement with a value of acSaveNo?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I have no problem closing a form without the dialog box from another form or from code, what I am trying to do is not have the dialog box when the user closes the application or form - either by closing the entire application or when windows is shutting down.

If the user clicks the X in the upper right hand corner of the screen, the save dialog box comes up. How do I avoid this?
 
If it were me, I would not allow the user to do that which you do not want them to do. I would remove and/or disable the close buttons from the various title bars.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
How do you remove the close button from the application? How do you handle the situation where the user is shutting down Windows which then tries to close the appliction generating a dialog box which prevents Windows from shutting down?
 
Have you tried to play with the Close event procedure of your form ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Yes,

I have put docmd.setwarnings false in the close and the unload events separately. It stops the dialog box which asks you whether you want to save but then gives you the form name dialog box. I don't want either.
 
To hide the close button on individual application forms, simply set the ControlBox and CloseButton properties of the form the False. To remove the Close button from the main Access window, use the following code (which as an added bonus shows how to change the text in the main Access Title bar).
Code:
Option Explicit
Option Compare Database

Dim fLng_OrigWindWord      As Long [COLOR=green]' The Original Access Style Word [/color]

Private Sub Form_Load()
   
   Dim lLng_HideAccessWord    As Long
   
[COLOR=green] ' Get the original Access Style Word and Save it [/color]
   fLng_OrigWindWord = GetWindowLong(hWndAccessApp, GWL_STYLE)
[COLOR=green] ' Remove the System Menu from the Title Bar [/color]
   lLng_HideAccessWord = fLng_OrigWindWord And (Not WS_SYSMENU)
   SetWindowLong hWndAccessApp, GWL_STYLE, lLng_HideAccessWord
[COLOR=green] ' Reset the TitleBar Text and Repaint the Access Window [/color]
   RedrawTitleBar "The New Title Bar for the Access Window"
   
End Sub

Private Sub Form_Unload(rInt_Cancel As Integer)
   
[COLOR=green] ' Reset the Access Window to its original Style [/color]
   SetWindowLong hWndAccessApp, GWL_STYLE, fLng_OrigWindWord
[COLOR=green] ' Reset the Titlebar Text and Repaint the Window [/color]
   RedrawTitleBar ""
   
End Sub
   
Private Sub RedrawTitleBar(rStr_TitleBarText As String)

   Dim lRct_WinPos         As RECT
   Dim lLng_WinWidth       As Long
   Dim lLng_WinHeight      As Long
   
[COLOR=green] ' Set the Title Bar Text [/color]
   SetWindowText hWndAccessApp, IIf((Len(rStr_TitleBarText) < 1), "Microsoft Access", rStr_TitleBarText)
   
[COLOR=green] ' Get the Access Current Window Position and Size [/color]
   GetWindowRect hWndAccessApp, lRct_WinPos
   With lRct_WinPos
[COLOR=green] ' Don't want Bottom and Right, but rather Width and Height [/color]
      lLng_WinWidth = .tLng_Right - .tLng_Left + 1
      lLng_WinHeight = .tLng_Bottom - .tLng_Top + 1
[COLOR=green] ' Repaint the Access Window [/color]
      MoveWindow hWndAccessApp, .tLng_Left, .tLng_Top, lLng_WinWidth, lLng_WinHeight, True
   End With
   
End Sub
And you'll need the following API Function declarations and Type structure.
Code:
Public Type RECT
    tLng_Left                 As Long
    tLng_Top                  As Long
    tLng_Right                As Long
    tLng_Bottom               As Long
End Type

Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Public Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top