Hi,
I have a database that was created by a colleague. They have created a form for adding client records onto the database.
This is done via a button that, when pressed, checks mandatory fields for correct entries and then saves the record.
However, when we do this, it is creating two identical records on the database.
She cannot see what she has done wrong in the code, and I know next to nothing about coding, so could someone please see the following code and let me know if anything obvious is in there that might be causing this problem?
Thank you.
I have a database that was created by a colleague. They have created a form for adding client records onto the database.
This is done via a button that, when pressed, checks mandatory fields for correct entries and then saves the record.
However, when we do this, it is creating two identical records on the database.
She cannot see what she has done wrong in the code, and I know next to nothing about coding, so could someone please see the following code and let me know if anything obvious is in there that might be causing this problem?
Thank you.
Code:
Private Sub CmdAdd_Click()
Dim dbAddClient As DAO.Database
Dim rstAddClient As DAO.Recordset
Set dbAddClient = CurrentDb
Set rstAddClient = dbAddClient.OpenRecordset("ClientInfo")
If IsNull(TxtForename.Value) Then
MsgBox "Enter a valid Forename", vbExclamation, "Cannot Save"
ElseIf IsNull(TxtSurname.Value) Then
MsgBox "Enter a valid Surname", vbExclamation, "Cannot Save"
ElseIf IsNull(TxtDB.Value) Then
MsgBox "Enter a valid Birth date", vbExclamation, "Cannot Save"
ElseIf IsNull(TxtProperty.Value) Then
MsgBox "Enter a valid Property Number/Name", vbExclamation, "Cannot Save"
ElseIf IsNull(TxtStreet.Value) Then
MsgBox "Enter a valid Street", vbExclamation, "Cannot Save"
ElseIf IsNull(TxtPostcode.Value) Then
MsgBox "Enter a valid Postcode", vbExclamation, "Cannot Save"
ElseIf IsNull(TxtTelNo.Value) Then
MsgBox "Enter a valid Contact Telephone number", vbExclamation, "Cannot Save"
ElseIf IsNull(CboArea.Value) Then
MsgBox "Enter a valid Area", vbExclamation, "Cannot Save"
ElseIf IsNull(TxtNINO.Value) Then
MsgBox "Enter a valid National Insurance Number", vbExclamation, "Cannot Save"
ElseIf IsNull(CboTenure.Value) Then
MsgBox "Enter whether client has their own house or rents", vbExclamation, "Cannot Save"
ElseIf IsNull(CboHowFunded.Value) Then
MsgBox "Enter how the clients service is funded", vbExclamation, "Cannot Save"
ElseIf IsNull(CboLevel.Value) Then
MsgBox "Enter a valid ID number", vbExclamation, "Cannot Save"
ElseIf IsNull(TxtAlertID.Value) Then
MsgBox "Enter a valid ID number", vbExclamation, "Cannot Save"
ElseIf IsNull(CboStatus.Value) Then
MsgBox "Enter clients status", vbExclamation, "Cannot Save"
ElseIf IsNull(TxtReviewDate.Value) Then
MsgBox "Enter date the client was reviewed", vbExclamation, "Cannot Save"
ElseIf IsNull(CboReferral.Value) Then
MsgBox "Enter a valid Referral Group", vbExclamation, "Cannot Save"
ElseIf IsNull(CboUrgent.Value) Then
MsgBox "Enter if client was an urgent install", vbExclamation, "Cannot Save"
ElseIf IsNull(CbocostAvoidance.Value) Then
MsgBox "Please fill cost avoidance field", vbExclamation, "Cannot Save"
ElseIf MsgBox("Save Member Details ?", vbOKCancel, "Confirmation") = vbOK Then
rstAddClient.AddNew
rstAddClient("Title").Value = CboTitle.Value
rstAddClient("Forename").Value = TxtForename.Value
rstAddClient("Surname").Value = TxtSurname.Value
rstAddClient("Date_of_Birth").Value = TxtDB.Value
rstAddClient("Property_Name").Value = TxtProperty.Value
rstAddClient("Street").Value = TxtStreet.Value
rstAddClient("Village").Value = TxtVillage.Value
rstAddClient("Town").Value = TxtTown.Value
rstAddClient("City").Value = TxtCity.Value
rstAddClient("Postcode").Value = TxtPostcode.Value
rstAddClient("TelephoneNo").Value = TxtTelNo.Value
rstAddClient("National_Insurance_No").Value = TxtNINO.Value
rstAddClient("AlertID").Value = TxtAlertID.Value
rstAddClient("SwiftNo").Value = TxtSwiftNo.Value
rstAddClient("OldID").Value = TxtOldID.Value
rstAddClient("Review_Date").Value = TxtReviewDate.Value
rstAddClient("Review_due_date").Value = TxtDueDate.Value
rstAddClient("Reviewed_by").Value = TxtReviewedBy.Value
rstAddClient("NOK_Name").Value = TxtNOKname1.Value
rstAddClient("NOK_telephone_no1").Value = TxtNOKTelNo1.Value
rstAddClient("NOK_telephone_no2").Value = TxtNOKTelNo2.Value
rstAddClient("Date_of_referral").Value = TxtDateRef.Value
rstAddClient("Time_of_Referral").Value = TxtTimeRef.Value
rstAddClient("Start_date_of_service").Value = TxtStart.Value
rstAddClient("GSM_Unit_Requested").Value = TxtGSMRequest.Value
rstAddClient("Install_completion_date").Value = TxtInstall.Value
rstAddClient("Installed_by").Value = TxtInstalledby.Value
rstAddClient("Reason_not_achieved").Value = TxtReason.Value
rstAddClient("End_date").Value = TxtEnd.Value
rstAddClient("DeInstall_date").Value = TxtDeInstall.Value
rstAddClient("NOK_Name").Value = TxtNOK2Name.Value
rstAddClient("NOK2_Telephone_No1").Value = TxtNOK2TelNo1.Value
rstAddClient("NOK2_Telephone_No2").Value = TxtNOK2TelNo2.Value
rstAddClient("sensor_requested").Value = TxtSensorRequest.Value
rstAddClient("Serial_number").Value = TxtSerial.Value
rstAddClient("Keysafe_requested").Value = TxtKeyRequest.Value
rstAddClient("KeysafeNo").Value = TxtKeyNo.Value
rstAddClient("Keysafe_position").Value = TxtPosition.Value
rstAddClient("Origin_of_data").Value = TxtOrigin.Value
rstAddClient("Checked_against_file").Value = TxtChecked.Value
rstAddClient("Moving_Levels").Value = TxtMoving.Value
rstAddClient("Fault_report_date").Value = TxtFaultReport.Value
rstAddClient("Fault_reason").Value = TxtFaultR.Value
rstAddClient("DS_plan_reviewed").Value = TxtDSPlan.Value
rstAddClient("Day_Support").Value = TxtDaySuppSent.Value
rstAddClient("Notes").Value = TxtNotes.Value
rstAddClient("Area").Value = CboArea.Value
rstAddClient("Alert_Level").Value = CboLevel.Value
rstAddClient("Area").Value = CboArea.Value
rstAddClient("Client_Status").Value = CboStatus.Value
rstAddClient("Referral_Group").Value = CboReferral.Value
rstAddClient("Urgent").Value = CboUrgent.Value
rstAddClient("Type_of_unit_installed").Value = CboUnitType.Value
rstAddClient("Level_Change").Value = CboChange.Value
rstAddClient("Sent_to").Value = CboSent.Value
rstAddClient("Day_support").Value = DaySupport.Value
rstAddClient("GSM_unit_present").Value = GSM.Value
rstAddClient("Install_target_achieved").Value = InstallTarget.Value
rstAddClient("Record_verified").Value = RecordVerified.Value
rstAddClient("Tenure").Value = CboTenure.Value
rstAddClient("HowFunded").Value = CboHowFunded.Value
rstAddClient("costAvoidance").Value = CbocostAvoidance.Value
rstAddClient("Smoke").Value = Smoke.Value
rstAddClient("InfaRed").Value = InfaRed.Value
rstAddClient("FallsIVI").Value = FallsIVI.Value
rstAddClient("Carbon").Value = Carbon.Value
rstAddClient("BogusCaller").Value = BogusCaller.Value
rstAddClient("BedChair").Value = BedChair.Value
rstAddClient("Exit").Value = PropExit.Value
rstAddClient("Temperature").Value = Temperature.Value
rstAddClient("Flood").Value = Flood.Value
rstAddClient("Gas").Value = Gas.Value
rstAddClient("Medication").Value = Medication.Value
rstAddClient("Epilepsy").Value = Epilepsy.Value
rstAddClient("Enuresis").Value = Enuresis.Value
rstAddClient("DDA").Value = DDA.Value
rstAddClient("CareAssist").Value = CareAssist.Value
rstAddClient("NoSensors").Value = NoSensors.Value
rstAddClient("Important").Value = TxtImportant.Value
rstAddClient.Update
'DoCmd.GoToRecord , , acNewRec
End If
End Sub