
Form Close Vs Close Window button problem
Hi,
This is one of the mayor pain in the necks i have to deal with also.
People don't care if you put a quit button the size of the screen, they will
close the program however they want, even sutting down windows if tey want
to, not way to keep them form doing it (without a lot of code, and even then
they can just pull the plug out of hte wall).
The way I deal with it, is rather than an on close or before save, etc. I
have all of the data write to a temp table, and i run all of the rutines on
my save button, close or quit.
If they close the form by any other way or mean, the data stays on the temp
table, if they did any changes and didn't comit they wouldn't be updated,
etc.
But the catch is that the next time they open the database, on the main form
i have code that checks the temp table, if it is there, i send them straight
there so that they can continue working on the last item. I though they
would hate this, but they actually love it. I took out a lot of the code I
use to have that prevented them from closing the form, and now everything
works fine. I actually use the same metode on all my projects since, and
even went back to the old ones and modify them to work like this.
hope it helps,
Rodrigo.
Quote:
> I have a form that is used both for data maintenance and addition. I use
> code behind a button to establish a blank record:
> DoCmd.GoToRecord , ,acNewRec
> The user inserts the needed data and uses an Access built button to do a
> save. Since the user may decide to close and not save the data there is a
> close button which just does a DoCmd.Close forcing everything through the
> form unload and form close. In form unload; I test for this case:
> Private Sub Form_Unload(Cancel As Integer)
> Dim strMsg As String
> Dim intStyle As Integer
> Dim strTitle As String
> Dim intResponse As Integer
> Dim a As Long
> If IsNull(Me.SerialNumber) Or Me.SerialNumber = 0 Then
> strMsg = "Are you sure you want to delete this new document?"
> intStyle = vbYesNo + vbInformation + vbDefaultButton2
> strTitle = "Close Action"
> intResponse = Msgbox(strMsg, intStyle, strTitle)
> If intResponse = vbYes Then
> DoCmd.RunCommand acCmdUndo
> End If
> End If
> End Sub
> This part works fine. The problem is when they use the Close Window
> button.(X)
> This brings me to the other half of the problem. The user requires that I
> maximize the form. Even through I have turned off the Min Max and control
> Box buttons. As soon as I do a DoCmd.Maximize they appear. I have found
no
> way to turn them off. Because of this I need both the Close window button
> and my close button to perform the same way. Popup is not an option since
> this will remove my user-defined menu.
> When I use the close window button I get the message asking if I want to
> delete the document from the form unload subroutine just as in the first
> case. Then the form fields are cleared at which time it tries to write the
> record, which then bounces on the validation rules requiring data. Why
does
> close window appears to try and commit the data record prior to running
the
> form unload I don't know.
> It seems that the record when we exit from close window is already
committed
> before it runs the form unload.
> I would appreciate any comments on this problem. I need to get rid of the
> close window button or at least find a way to process/trap it for
> processing.
> TomB