I have a data entry form called "frmAddDependant" and it is opened with a button with the VB code line:
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:
Also I forgot to mention that in the Form_Open function of "frmAddDependant" I have the following code:
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?
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?