Exit From with required fields

Profector

Registered User.
Local time
Today, 07:15
Joined
Mar 15, 2006
Messages
33
I have a failry simple data entry form that autonumbers the primarykey, and has a field for a name, date, and some text. All the fields are required. The form works fine if everything is entered as required. My problem happens when I try to exit the form when all the required fields are not complete.

I've trapped the error so I can't exit without the form being completed with if's and else if's, but how about when I get half way through the form and decide I don't want to contiue I just want to exit out and delete everything?


I've tried

'DoCmd.SetWarnings False
'DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
'DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
'DoCmd.Close

and

'DoCmd.RunCommand acCmdDeleteRecord
'DoCmd.Close

and some type of sql command that deleted every in the table.... including the stuff that I wanted to keep.



I have a feeling i'm not even close and going about it in the worng way. Any ideas?
 
I find it bet to use the form's before update event.

Example:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)



' perform data validation
If IsNull(Me.CompanyName) Then

   MsgBox "You must enter a Company Name.", vbCritical, "Data entry error..."
   DoCmd.GoToControl "CompanyName"
      
   Cancel = True

End If


If Not Cancel Then
  ' passed the validation process

    If Me.NewRecord Then
        If MsgBox("Data will be saved, Are you Sure?", vbYesNo, "Confirm") = vbNo Then
            Cancel = True
        Else
            ' run code for new record before saving
        
        End If
    
    
    Else
        If MsgBox("Data will be modified, Are you Sure?", vbYesNo, "Confirm") = vbNo Then
            Cancel = True
        Else
           ' run code before an existing record is saved
           ' example: update date last modified
            
        End If
    End If

End If


' if the save has been canceled or did not pass the validation , then ask to Undo changes
If Cancel Then

    If MsgBox("Do you want to undo all changes?", vbYesNo, "Confirm") = vbYes Then
        Me.Undo

    End If
    
End If



End Sub
 
Sorry for the newb questions. I usaully just create reports based on data that someone else entered already.

On my form it seems the record is created as soon as I type something in any box, and at the same time it seems the primary key is created. My thought process tells me the only way to exit the form without completing everything is to delete everything else the form won't exit without errors. Is there another way?

At what point does the "update" happen? The update sounds like it expects there to be existing data already in the record. May i'm not understanding what the update does. I've try to read more on it.

My form only creates new records. Once the user completes the form they can't get back in to change it. Once they open the form again it's empty waiting for someone to enter the data and click Exit.

The goal of this form is to allow users to log customer compliants. These users wouldn't normally have access to all of the complaints.

Thanks for reading.
 

Users who are viewing this thread

Back
Top Bottom