ShabanaHafiz
Programmer
I am using MS Office Access 2003.
I created a table (name: Item) with three fields; ItemID, Active and Description. ItemID is Primary Key. Then I created a form (name: Item) and chose Item table in New Form dialog box. In the form, Item (Combo Box), Active (Text Box) and Description (Text Box) are displayed. Form has two command buttons cmdAddRecord and cmdSaveRecord.
cboItemID has a Row Source property set to Item. What I need to accomplish is when a user selects an existing ItemID from cboItemID instead of adding a new record, then all attributes of that record should be populated on the form.
I wrote the following code in cboItemID AfterUpdate event:
When this code is executed, I get a Run-time error ‘3022’ at the execution of this line:
Error Message is:
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship.
I created a table (name: Item) with three fields; ItemID, Active and Description. ItemID is Primary Key. Then I created a form (name: Item) and chose Item table in New Form dialog box. In the form, Item (Combo Box), Active (Text Box) and Description (Text Box) are displayed. Form has two command buttons cmdAddRecord and cmdSaveRecord.
cboItemID has a Row Source property set to Item. What I need to accomplish is when a user selects an existing ItemID from cboItemID instead of adding a new record, then all attributes of that record should be populated on the form.
I wrote the following code in cboItemID AfterUpdate event:
Code:
Private Sub cboItemID_AfterUpdate()
Dim rs As Object
If Not Me.NewRecord Then
Set rs = Me.Recordset.Clone
rs.FindFirst "[ItemID] = '" & Me![cboItemID] & "'"
If Not rs.EOF Then
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End If
End Sub
When this code is executed, I get a Run-time error ‘3022’ at the execution of this line:
Code:
Me.Bookmark = rs.Bookmark
Error Message is:
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship.