[SOLVED] Index or duplicate key violation

mercredi 1 avril 2015

Hello Experts,

what am I not seeing? It must be so obvious that it baffles me.I am trying to add a "T" in front of an article number and write this new number to a table.

Access cannot find the new Article strArt because it does not exist. When I put a msgbox after "if .nomatch then" it correctly shows the message. Yet it refuses to create the new record because of a key/index violation. Apart from an index on the recordkey, it has an index on Artno, both indexes do not (obviously) want duplicate values.



Here is the code:

Private Sub btnCopyT_Click()

Dim db As Database

Dim rstArt As Recordset

Dim strArt As String

Set db = CurrentDb

strArt = "T" & Me.frmNomenclatuurSubfrm.Form.Artno

Set rstArt = db.OpenRecordset("tblArticle", dbOpenDynaset)

With rstArt

.FindFirst "Artno = '" & strArt & "'"

If .NoMatch Then

rstArt.AddNew

!Artno = strArt

rstArt.Update

End If

End With



End Sub

[SOLVED] Index or duplicate key violation

0 commentaires:

Enregistrer un commentaire

Labels