CancelEvent
Feb 8, 2006
I have the next code:
Private Sub Form_Close()
Set db = CurrentDb
Set rd = db.OpenRecordset("OrderTable")
With rd
Do While Not .EOF
If rd.Fields("Order") = -1 Then
msgbox "There are still some order's", VbOkOnly
docmd.CancelEvent
Exit Do
else
rd.MoveNext
end if
loop
end with
end sub
The field "Order" is a checkbox and if there's still one on value -1, the form will still close!
Has anyone an idea if there is a way to not close the form??
Ps I can't use a button because I'm using a datasheetform
View Replies
Aug 5, 2005
Hi,
I've the following code but the cancel doesn't seem to be working, when upon click cancel, it should still remain on the form but it closed the form. Can someone please advise.
Dim strMsg As String
Dim strMsg2 As String
Dim strTitle As String
Dim strTitle2 As String
Dim intResponse As Integer
strMsg = "Do you wish to save changes?"
strMsg2 = "The changes you made were not saved."
strTitle = "Save Entry"
strTitle2 = "Entry Canceled"
If Me.Dirty Then
intResponse = MsgBox(strMsg, vbYesNoCancel, strTitle)
If intResponse = vbNo Then
Me.Undo
MsgBox strMsg2, vbOKOnly, strTitle2
ElseIf intResponse = vbCancel Then
DoCmd.CancelEvent
Me.SetFocus
End If
End If
View 1 Replies
View Related
Sep 15, 2004
I have a form that automatically adds a EmployeeID if one doesn't exist and allows the user to enter a name, etc. The problem is, many employees mess up writing their ID on the order forms or write someone elses. To avoid multiple entries being entered without knowing it, I made a form pop up listing duplicates if there are any. If the user tries to exit the form without taking care of the problem, I want them to have trouble doing it so they are sure they want to leave duplicates for whatever reason.
The problem: The following code is what I wrote as an event for On Close of my duplicates form, but after choosing "Yes", the form still closes instead of staying open (After running my "It's working" message)....
Code:Private Sub Form_Close()Dim db As ObjectDim rst As ObjectDim sqlrst As Stringsqlrst = "select Employees.FirstName, Employees.LastName from Employees where (((Employees.FirstName)='" & Me.FirstName & "') AND ((Employees.LastName)='" & Me.LastName & "'))"Set db = Application.CurrentProject.ConnectionSet rst = CreateObject("ADODB.Recordset")rst.Open sqlrst, db, 1 ' 1 = adOpenKeysetIf rst.RecordCount > 0 Then If MsgBox("Closing this form now will allow duplicate employee names! Would you like to delete the duplicate entries now? Please press Yes and delete any duplicates.", vbYesNo) = vbYes ThenGoTo CancelEnd IfEnd IfDoCmd.RunSQL "DELETE Lookup.* FROM Lookup"GoTo TheEndCancel:MsgBox "It's Working"DoCmd.CancelEventDoCmd.OpenForm "USAAemployeesDup"TheEnd:End Sub
Any help on this would be greatly appreciated!
Regards,
Philip.
View 5 Replies
View Related