Suresh1957
New member
- Local time
- Today, 09:16
- Joined
- Feb 28, 2024
- Messages
- 3
I get error as "the changes you requested to the table were successful because they would create duplicate values in the index, primary key or relationship" when I try to insert a record into local table, details gathered from a form. My exposure to computer programming is only functional and not exhaustive. I learnt this as a hobby after my retirement. So, please bear with me if I sound unprofessional or not worthy of this community. The code is as follows:
Dim sqlInsrt As String
Dim rstDbase As DAO.Recordset
Dim sqldbase As String
sqldbase = "Select * from LifeMembersTemp order by StaffNo"
Set rstDbase = CurrentDb.OpenRecordset(sqldbase, dbOpenDynaset, dbSeeChanges)
Dim zStaffNo As Long
zStaffNo = Me.txtLMStaffNo
Dim rstLife As DAO.Recordset
Dim sqlLife As String
sqlLife = "Select * from dbo_LifeMembers where StaffNo=""" & zStaffNo & """"
Set rstLife = CurrentDb.OpenRecordset(sqlLife, dbOpenDynaset, dbSeeChanges)
If rstLife.RecordCount = 0 Then
rstDbase.AddNew
rstDbase!MemGender = Me.txtMEMGENDER
rstDbase!MemName = Me.txtMemName
'rstDbase!NOMGENDER = Me.txtNOMGENDER
rstDbase!Spouse = Me.txtASSONAME
Me.txtNominee = Me.txtASSONAME
rstDbase!Add1 = Me.txtAdd1
rstDbase!Add2 = Me.txtAdd2
rstDbase!Add3 = Me.txtAdd3
rstDbase!Place = Me.txtPlace
rstDbase!Pincode = CLng(Me.txtPin)
rstDbase!Mobile = Me.txtMOBILENO
rstDbase!District = Me.txtDistrict
rstDbase!Email = Me.txtEmail
rstDbase!State = Me.txtState
rstDbase!Scale = Me.cmbScale
rstDbase!MemDOB = Me.txtMEMDOB
rstDbase!LastWorked = Me.txtBranch
Nz (rstDbase!MemDOJ = Me.txtDOJ)
rstDbase![Felicitation75] = Me.txtFeli75
rstDbase![Felicitation90] = Me.txtFeli90
rstDbase![LastCircle] = Me.txtCircle
rstDbase![MemDOR] = Me.txtDOR
rstDbase![PenPf] = Me.cmbPenPF
rstDbase!Mode = Me.cmbMode
If Me.txtDOD = Null Or Me.txtDOD = "" Then
rstDbase!MemDOD = Null
End If
rstDbase!PPONumber = Me.txtPPO
rstDbase![PenAccount] = Me.txtPENACCOUNT
If Me.txtResign = "" Or Me.txtResign = Null Then
rstDbase!MemExitDate = Null
End If
rstDbase!STAFFNO = Me.txtLMStaffNo
If Me.txtAssoNum = "" Then
rstDbase!ASSONUM = Null
End If
rstDbase!MEMNO = Me.txtMemNo
Nz (rstDbase!DtOfEnrol = Me.txtEnrollDt)
rstDbase!MemType = Me.txtMEMTYPE
rstDbase!MemStatus = Me.txtMEMSTATUS
rstDbase!Updated = Now()
'AT THIS POINT I GET ERROR
rstDbase.Update
MsgBox "Record with Membership No : " & Me.txtMemNo & "added !", vbExclamation
DoCmd.RunCommand acCmdSaveRecord
Else
MsgBox "Data Already Exists! Add New Member process aborted!", vbExclamation
End If
Dim sqlInsrt As String
Dim rstDbase As DAO.Recordset
Dim sqldbase As String
sqldbase = "Select * from LifeMembersTemp order by StaffNo"
Set rstDbase = CurrentDb.OpenRecordset(sqldbase, dbOpenDynaset, dbSeeChanges)
Dim zStaffNo As Long
zStaffNo = Me.txtLMStaffNo
Dim rstLife As DAO.Recordset
Dim sqlLife As String
sqlLife = "Select * from dbo_LifeMembers where StaffNo=""" & zStaffNo & """"
Set rstLife = CurrentDb.OpenRecordset(sqlLife, dbOpenDynaset, dbSeeChanges)
If rstLife.RecordCount = 0 Then
rstDbase.AddNew
rstDbase!MemGender = Me.txtMEMGENDER
rstDbase!MemName = Me.txtMemName
'rstDbase!NOMGENDER = Me.txtNOMGENDER
rstDbase!Spouse = Me.txtASSONAME
Me.txtNominee = Me.txtASSONAME
rstDbase!Add1 = Me.txtAdd1
rstDbase!Add2 = Me.txtAdd2
rstDbase!Add3 = Me.txtAdd3
rstDbase!Place = Me.txtPlace
rstDbase!Pincode = CLng(Me.txtPin)
rstDbase!Mobile = Me.txtMOBILENO
rstDbase!District = Me.txtDistrict
rstDbase!Email = Me.txtEmail
rstDbase!State = Me.txtState
rstDbase!Scale = Me.cmbScale
rstDbase!MemDOB = Me.txtMEMDOB
rstDbase!LastWorked = Me.txtBranch
Nz (rstDbase!MemDOJ = Me.txtDOJ)
rstDbase![Felicitation75] = Me.txtFeli75
rstDbase![Felicitation90] = Me.txtFeli90
rstDbase![LastCircle] = Me.txtCircle
rstDbase![MemDOR] = Me.txtDOR
rstDbase![PenPf] = Me.cmbPenPF
rstDbase!Mode = Me.cmbMode
If Me.txtDOD = Null Or Me.txtDOD = "" Then
rstDbase!MemDOD = Null
End If
rstDbase!PPONumber = Me.txtPPO
rstDbase![PenAccount] = Me.txtPENACCOUNT
If Me.txtResign = "" Or Me.txtResign = Null Then
rstDbase!MemExitDate = Null
End If
rstDbase!STAFFNO = Me.txtLMStaffNo
If Me.txtAssoNum = "" Then
rstDbase!ASSONUM = Null
End If
rstDbase!MEMNO = Me.txtMemNo
Nz (rstDbase!DtOfEnrol = Me.txtEnrollDt)
rstDbase!MemType = Me.txtMEMTYPE
rstDbase!MemStatus = Me.txtMEMSTATUS
rstDbase!Updated = Now()
'AT THIS POINT I GET ERROR
rstDbase.Update
MsgBox "Record with Membership No : " & Me.txtMemNo & "added !", vbExclamation
DoCmd.RunCommand acCmdSaveRecord
Else
MsgBox "Data Already Exists! Add New Member process aborted!", vbExclamation
End If