Code: DoCmd.OpenForm "frmAddDependant", , , , acFormAdd, , Me.IDWell, "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.CloseAlso 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 SubSo 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: Private Sub rmAddIncident_Click() Dim err As Integer Dim cnn1 As ADODB.Connection Dim Risk_Data As ADODB.Recordset Dim strCnn As String 'Check that all fields are filled in rmENCON.SetFocus If rmENCON.Text = "" Then err = err + 1 MsgBox "Please fill in the ENCON number." & err End If rmName.SetFocus If rmName.Text = "" Then err = err + 1 MsgBox "Please fill in the name of the person affected by the incident." End If rmDate.SetFocus If rmDate.Text = "" Then err = err + 1 MsgBox "Please fill in the date the incident occured." End If rmInjury.SetFocus If rmInjury.Text = "" Then err = err + 1 MsgBox "Please specify the degree of injury." End If rmComments.SetFocus If rmComments.Text = "" Then err = err + 1 MsgBox "Please briefly describe the incident in the comments box." End If rmResolved.SetFocus If rmResolved.Text = "" Then err = err + 1 MsgBox "Please briefly summarize the follow-up." End If rmVictimstatus.SetFocus If rmVictimstatus.Text = "" Then err = err + 1 MsgBox "Please fill in the Victim status." End If rmLocation.SetFocus If rmLocation.Text = "" Then err = err + 1 MsgBox "Please fill in the location the incident took place." End If rmType.SetFocus If rmType.Text = "" Then err = err + 1 MsgBox "Please incicate the type of incident that occured." End If rmSpecificType.SetFocus If rmSpecificType.Text = "" Then err = err + 1 MsgBox "Please incicate the specific type of incident that occured." End If 'if no errors insert data If err < 1 Then ' Open a connection. Set cnn1 = New ADODB.Connection mydb = "G:AdminCeoHuman ResourcesRISKMGMTInhouse dataRisk DatabaseInhouse Data.mdb" strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb cnn1.Open strCnn ' Open Risk_Data table. Set Risk_Data = New ADODB.Recordset Risk_Data.CursorType = adOpenKeyset Risk_Data.LockType = adLockOptimistic Risk_Data.Open "Risk_Data", cnn1, , , adCmdTable 'get the new record data Risk_Data.AddNew Risk_Data!ENCON = rmENCON Risk_Data!Name = rmName Risk_Data!Date = rmDate Risk_Data!Injury = rmInjury Risk_Data![Incident Comments] = rmComments Risk_Data![Medication Risk] = Med_Risk Risk_Data![Medication/Equipment] = rmMedication Risk_Data![Victim Status] = rmVictimstatus Risk_Data!Location = rmLocation Risk_Data!Type = rmType Risk_Data![Specific Type] = rmSpecificType Risk_Data![Phys/Empl/Pt Involved] = rmPersonInvolved Risk_Data![Follow-up Summary] = rmResolved Risk_Data![Resolved or Pending] = ResolvedOrPending Risk_Data![Date Resolved] = rmDateResolved Risk_Data.Update 'Show the newly added data. MsgBox "Incident #: " & Risk_Data!ENCON & " has been successfully added" 'close connections to DB. Risk_Data.Close cnn1.Close 'clear all objects Me.rmENCON.Value = "" Me.rmDate.Value = "" Me.rmName.Value = "" Me.rmInjury.Value = "" Me.rmComments.Value = "" Me.Med_Risk.Visible = False Me.rmMedication.Value = "" Me.rmLocation.Value = "" Me.rmVictimstatus.Value = "" Me.rmType.Value = "" Me.rmSpecificType.Value = "" Me.rmPersonInvolved.Value = "" Me.rmResolved.Value = "" Me.ResolvedOrPending.Value = "" Me.rmDateResolved.Value = "" 'send back to main page. DoCmd.OpenForm "Main_Page" Else MsgBox "An Error has occurred, please check and try again" End If DoCmd.Close acForm, "Enter_New_Incident" End SubAnyone see anything in there that would be causing this issue. Its not a huge deal, but a pain in the butt to get rid of the blanks.