I'm working on a project for school where I'm using a form to add/edit records in an Access database table. AccountID is the Primary Key used to link different tables, so I can't have duplicates of it. The AccountIDs are in a drop down list box on the form. Right now my code is: `
Option Compare Database
Private Sub btnAddRecord_Click()
'Declare variables
Dim db As DAO.Database
Dim rst As Recordset
'Set the current database
Set db = Application.CurrentDb
'Set the recordset
Set rst = db.OpenRecordset("tblHOAFees")
'Cycle through records
Do While Not rst.EOF
If rst!AccountID = lstAccountID.Value Then
rst.Edit
rst!HOAID = txtHOAID.Value
rst!Location = txtLocation.Value
rst!House = chkHouse.Value
rst!Rooms = txtRooms.Value
rst!SquareFeet = txtSquareFeet.Value
rst!HOAFees = txtHOAFees.Value
rst.Update
Else
rst.AddNew
rst!AccountID = lstAccountID.Value
rst!HOAID = txtHOAID.Value
rst!Location = txtLocation.Value
rst!House = chkHouse.Value
rst!Rooms = txtRooms.Value
rst!SquareFeet = txtSquareFeet.Value
rst!HOAFees = txtHOAFees.Value
rst.Update
End If
Loop
End Sub
` Right now when I select an AccountID from my list I keep getting Runtime error '3022'. It's saying my changes would create duplicates in the value index. I'm stuck, any help would be appreciated.
I've tried changing .Value to .Text, but I got a different error for that.