Good morning,
I have a form which has a button on it which is meant to close the form without saving any changes to the form. The caviat is that I want to check to see if the form is empty, and if so, delete the record (I am really only looking at 4 key fields).
So what I am looking at are three scenarions:
1) when the user clicks the button, all four fields are null. In this case, the record gets deleted.
2) when the user clicks the close button, the four fields are filled in. In this case I want to undo the changes to the form.
2A) once the changes have been undone, if the 4 fields are null, delete the record, close the form
2B) once the changes have been undone, if the 4 fields are not null, keep the record (without changes), close the form
The code currently looks like this. I can get scenario 1 and 2B to work, but not 2A. It gets as far as undoing the changes and then closes the form. It skips the second if statement. I am not a programmer, and I bet this is something really stupid that is tripping me up.
Private Sub Command366_Click()
Dim canVal As Integer
Dim SOAValue As Boolean
Dim VSValue As Boolean
Dim PDValue As Boolean
Dim InitValue As Boolean
SOAValue = IsNull(Combo326)
VSValue = IsNull(Combo354)
PDValue = IsNull(Text127)
InitValue = IsNull(Text257)
canVal = MsgBox("You have elected to close the form without saving." & vbCr & vbCr & "Are you sure you want to continue?", vbYesNo + vbExclamation, "Close Form")
If canVal = vbNo Then
DoCmd.CancelEvent
ElseIf canVal = vbYes Then
MsgBox "SOA = " & SOAValue & " & VS = " & VSValue & " & PD = " & PDValue & " & Init = " & InitValue, vbInformation + vbOKOnly
If (SOAValue = False) And (VSValue = False) And (PDValue = False) And (InitValue = False) Then
MsgBox "4 field filled in", vbOKOnly + vbInformation, "Returning to Main"
Me.Undo
MsgBox "removed changes", vbOKOnly + vbInformation, "Returning to Main"
End If
If (SOAValue = True) Or (VSValue = True) Or (PDValue = True) Or (InitValue = True) Then
MsgBox "This is not a complete record, it will be deleted", vbOKOnly + vbInformation, "Record to be Deleted"
Me.Undo
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
MsgBox "Record Deleted", vbOKOnly + vbInformation, "Delete"
End If
DoCmd.Close acForm, "CARForm"
End If
End Sub
Your help would be appreciated.
thanks
Chris