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!

form adding values to table when not supposed to 1

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I have a form where a user can enter information, hit a cmd button and have that information saved into a table. I am trying to make my form more robust and I'm running into a few problems.

I want to make it so when the user hits the close button (the X in the top right corner), and if there is information in the form, a msgbox will pop up and ask the user if he/she really wants to close the form. If he hits "Yes" then everything works fine. The form closes and the information is not saved in the table. However, if the user says "No" then the form stays open, but the information is added to the database table. Any ideas on how to get this to not happen? My code is a little confusing, but I'll put some up here. Thanks!


'### FORM BEFORE UPDATE ###
Private Sub Form_BeforeUpdate(Cancel as Integer)
If(FormClean=true) or (recsaved=true) Then
'Skip this next part
Else
UserResponse = MsgBox ("Do you want to close?",vbYesNoCancel)
If (UserResponse = 6) Then '### YES ###
Me.Undo
keepopen=False
Else '### NO/CANCEL ###
keepopen=true
GetFormVariables 'Function to store all entries in form in variables
End If
End if
End Sub




'### FORM UNLOAD ###
Private Sub Form_Unload(Cancel as Integer)
If (keepopen=true) then
Cancel=True
SetFormVariables 'Function to return variables to controls on form
ClearFormVariables
Else
Cancel=False
End if
keepopen=false
End Sub






 
I have a simular situation. This is what I use.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Changes have been made. Do you wish to update?", vbYesNo) = vbYes Then
'Do nothing
Else
Me.Undo
End If

End Sub ljprodev@yahoo.com
ProDev, MS Access Applications
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top