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

Close a form and do not add a new record

Status
Not open for further replies.
Jan 22, 2001
124
US
Hi

This question "should" have an easy solution, but I'm having a difficult time coming up with one. I have a maximized form in which I enter new records. Because the form is maximized (and I'm using Access '97), the 'close (x)' button in the 'control box' on the right hand corner of the form, cannot be deactivated. Well, if the user decides to close the form without using the save/close command button I created, I do not want the record added to the database. Any ideas on how to accomplish this? Any help would be greatly appreciated. Thanks in advance.
 
Hi!

I don't know if there is an easier solution or not, but you can try this:

Declare a form level Boolean variable

In the Form_Current procedure use the code:

Variable = False

In your buttons click event procedure, the first thing you do is set the variable equal to true. Finally, in your Form_BeforeUpdate procedure add this code:

If Variable = False Then
Me.Undo
Else
Put the code you already have in the procedure here
End If

hth
Jeff Bridgham
 
Hi!

I solved this following:
I declared Boolean type variable (e.g. blnAllowClose and included code below:

1. In the Form close button's On Click procedure:

dim blnAllowClose as boolean

private sub cmdClose_Click()
blnAllowClose=True

'Your code
end sub


2. In the Form Unload procedure:

private sub form_Unload(cancel as integer)
if not blnAllowClose then
'If wasn't pushed Close button
'unload action is cancelled

cancel=true
end if
end sub


Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top