Adding Multiple Records to Table using Recordset
Hi, Basically i have a an unbounf form where data is entered and added to a single table using teh add recordset function. I have it working at the moment where it can add 1 set of data. I would like to add multiple records. i get this error Message "the changes you requested to the table were not successful beacuse they would create duplicate values in the index, primary. change the data in the fields"
Code:
Private Sub cmdSave_Click()
Dim rstAQ As DAO.Recordset
Set rstAddQ = dbase.OpenRecordset("tblAQ", dbOpenDynaset)
If is null(txtScore) Then
MsgBox "Please Enter a Score", vbExclamation, "Cannot Save"
Else
rstAddQ.AddNew
rstAddQ("AQID") = newNumber0("AQ")
rstAddQ("Score") = txtScore.Value
rstAddQ("Notes") = txtNotes.Value
rstAddQ("M Score") = txtMScore.Value
rstAddQ("Product Name") = txtPName.Value
rstAddQ("ID") = txtID.Value
rstAddQ("PCategory") = txtPcat.Value
rstAddQ.Update
rstAddQ.Bookmark = rstAddQ.LastModified
End If
''''''I had the above code workin on its own when i inserted the code below it crashed''''
If Not IsNull(cbo1.Value) Then
rstAddQ.AddNew
rstAddQ("AQID") = newNumber0("AQ")
rstAddQ("Score") = txtScore.Value
rstAddQ("Notes") = txtNotes.Value
rstAddQ("M Score") = txtMScore.Value
rstAddQ("Brand") = cbo1.Column(1)
rstAddQ("Product Name") = cbo1.Column(2)
rstAddQ("ID") = cbo1.Column(0)
rstAddQ("PCategory") = cbo1.Column(3)
rstAddQ.Update
rstAddQ.Bookmark = rstAddQ.LastModified
End If
Hi, Basically i have a an unbounf form where data is entered and added to a single table using teh add recordset function. I have it working at the moment where it can add 1 set of data. I would like to add multiple records. i get this error Message "the changes you requested to the table were not successful beacuse they would create duplicate values in the index, primary. change the data in the fields"
Code:
Private Sub cmdSave_Click()
Dim rstAQ As DAO.Recordset
Set rstAddQ = dbase.OpenRecordset("tblAQ", dbOpenDynaset)
If is null(txtScore) Then
MsgBox "Please Enter a Score", vbExclamation, "Cannot Save"
Else
rstAddQ.AddNew
rstAddQ("AQID") = newNumber0("AQ")
rstAddQ("Score") = txtScore.Value
rstAddQ("Notes") = txtNotes.Value
rstAddQ("M Score") = txtMScore.Value
rstAddQ("Product Name") = txtPName.Value
rstAddQ("ID") = txtID.Value
rstAddQ("PCategory") = txtPcat.Value
rstAddQ.Update
rstAddQ.Bookmark = rstAddQ.LastModified
End If
''''''I had the above code workin on its own when i inserted the code below it crashed''''
If Not IsNull(cbo1.Value) Then
rstAddQ.AddNew
rstAddQ("AQID") = newNumber0("AQ")
rstAddQ("Score") = txtScore.Value
rstAddQ("Notes") = txtNotes.Value
rstAddQ("M Score") = txtMScore.Value
rstAddQ("Brand") = cbo1.Column(1)
rstAddQ("Product Name") = cbo1.Column(2)
rstAddQ("ID") = cbo1.Column(0)
rstAddQ("PCategory") = cbo1.Column(3)
rstAddQ.Update
rstAddQ.Bookmark = rstAddQ.LastModified
End If
Last edited: