I need to cancel or delete the current NEW record from saving when closed, but only when certain criteria is being met. It seems simple enough where I should be able to figure out by myself, but I can't get it right to cancel under my certain circumstances. What I need is for... If my orders form is opened from the customers form, and no new data has been entered, then cancel/delete that order when the form is closed.
Background info...
The customers form passes an openargs value when opening the orders form to auto-fill customer data in that form. So a way to tell that the orders form has been opened form the customers form is If not isnull(me.openargs)... and I know the way to tell if the form has been modified is something like If me.dirty ...., but when I put them together in the onclose event, noting happens.
Private Sub Form_Close()
If Not IsNull(Me.OpenArgs) And Me.NewRecord Then
If msgbox("do you want to cancel",vbYesNo) Then
DoCmd.RunCommand acCmdUndo
End If
End If
I did some searching around these posts and read to put the code in the beforeupdate event, which works better, but if the user DOES want to continue entering the order, whenever they click in the subform of the orders form (btw, which is where the first field they would be entering data in after the form is opened from the customers form), the cancel/delete prompt displays. I cannot figure out how to cancel the entry only under those circumstances listed above. Can anyone help me?
Background info...
The customers form passes an openargs value when opening the orders form to auto-fill customer data in that form. So a way to tell that the orders form has been opened form the customers form is If not isnull(me.openargs)... and I know the way to tell if the form has been modified is something like If me.dirty ...., but when I put them together in the onclose event, noting happens.
Private Sub Form_Close()
If Not IsNull(Me.OpenArgs) And Me.NewRecord Then
If msgbox("do you want to cancel",vbYesNo) Then
DoCmd.RunCommand acCmdUndo
End If
End If
I did some searching around these posts and read to put the code in the beforeupdate event, which works better, but if the user DOES want to continue entering the order, whenever they click in the subform of the orders form (btw, which is where the first field they would be entering data in after the form is opened from the customers form), the cancel/delete prompt displays. I cannot figure out how to cancel the entry only under those circumstances listed above. Can anyone help me?