Data entry form saves new record even with no input...

SimonSezz

Registered User.
Local time
Today, 12:46
Joined
Jun 19, 2008
Messages
30
I have a data entry form called "frmAddDependant" and it is opened with a button with the VB code line:

Code:
DoCmd.OpenForm "frmAddDependant", , , , acFormAdd, , Me.ID

Well, "frmAddDependant" then opens and I can add the new entry and it shows up as a new record in the appropriate table. The problem is if the user doesn't input anything and just clicks the "Back" button (which takes them back to the previous form), it still creates a new record that is completely blank. For the "Back" button I am just using the code:

Code:
DoCmd.Close

Also I forgot to mention that in the Form_Open function of "frmAddDependant" I have the following code:

Code:
Private Sub Form_Open(Cancel As Integer)
    DoCmd.RunCommand acCmdRecordsGoToNew
    Me.EmployeeID = Me.OpenArgs
End Sub

So I am trying to figure out how to not save it as a new record if the user doesn't enter the proper information. I could either make some adjustments in the table design and make the fields required (currently only the ID field is required and that is an Autonumber and the primary key)... or I can create a function in the Form_Close function that would check if the form is "dirty" and if it isn't then it won't save the record, but how would I do that? Or is there some obvious solution that I am missing?
 
The problem is this line

Code:
Me.EmployeeID = Me.OpenArgs

in the On Open event and it causes the record to become dirty so it will be saved.

I would move the line to the Form's Before Update event.
 
It appears to work now that I moved the line to the Before Update event. Thanks!
 

Users who are viewing this thread

Back
Top Bottom