Hello,
I have a code in my database to add a new record into a table.
The primary key is the RefID and I have this field in the form so the user can scroll through records within the form.
When a record is added from the form into a table, I have it coded to go to the next record with various fields copied from the prior record into the new record. However, when a new record is ready to be populated with the remaining fields, I've noticed that the RefID goes from 39 to 42. It skips a record or two. So when I go to look at the table. I see a record added for 40, record 41 is skipped and the new record added is 42. Did I so something wrong with my code?
Thank you
I have a code in my database to add a new record into a table.
The primary key is the RefID and I have this field in the form so the user can scroll through records within the form.
When a record is added from the form into a table, I have it coded to go to the next record with various fields copied from the prior record into the new record. However, when a new record is ready to be populated with the remaining fields, I've noticed that the RefID goes from 39 to 42. It skips a record or two. So when I go to look at the table. I see a record added for 40, record 41 is skipped and the new record added is 42. Did I so something wrong with my code?
Code:
Private Sub Add_Record_Click()
Dim strNotes As String
Dim strOutliers As String
Dim strOther As String
Dim MyFirstField As String
Dim MySecondField As String
Dim MyThirdField As String
Dim MyFouthField As String
Dim MyFifthField As String
Dim MySixthField As String
Dim MySeventhField As String
Dim MyEigthField As String
Dim MyNinthField As String
Dim MyTenthField As String
If IsNull(Me.Notes) Then
strNotes = "Null"
Else
strNotes = "'" & Me.Notes & "'"
End If
If IsNull(Me.Outliers) Then
strOutliers = "Null"
Else
strOutliers = "'" & Me.Outliers & "'"
End If
If IsNull(Me.txtOther) Then
strOther = "Null"
Else
strOther = "'" & Me.txtOther & "'"
End If
CurrentDb.Execute "INSERT INTO QAMaster([Entered By],[Cycle Month], [Report Type], [Date Reviewed], [Reviewer Type], [Reviewer], [Reviewer Report Area], [Main Section], [Topic Section], [Ownership], [Count], [Priority], [Approved By], [L1], [L2], [L3], [Other], [Exception], [Notes], [Outliers])" & _
"VALUES ('" & Me.EnteredBy & "', '" & Me.CycleMonth & "', '" & Me.ReportType & "', '" & Me.DateReviewed & "', '" & Me.ReviewerType & "', '" & Me.Reviewer & "', '" & Me.ReviewerReportArea & "', '" & Me.MainSection & "', '" & Me.TopicSection & "', '" & Me.Ownership & "', '" & Me.txtCount & "', '" & Me.PriorityLevel & "', '" & Me.Approved & "','" & Me.L1 & "', '" & Me.L2 & "', '" & Me.L3 & "', '" & Me.txtOther & "', '" & Me.Exception & "', '" & Me.Notes & "', '" & Me.Outliers & "');", dbFailOnError
MsgBox "Record Added Successfully", vbInformation, "SUCCESS!"
'Copy fields to variables
MyFirstField = Me.EnteredBy
MySecondField = Me.CycleMonth
MyThirdField = Me.DateReviewed
MyFouthField = Me.ReportType
MyFifthField = Me.ReviewerType
MySixthField = Me.Reviewer
MySeventhField = Me.ReviewerReportArea
MyEigthField = Me.Ownership
MyNinthField = Me.MainSection
MyTenthField = Me.TopicSection
'Go to New Record
DoCmd.GoToRecord , , acNewRec
'Reverse the process and plug old values into new record
Me.EnteredBy = MyFirstField
Me.CycleMonth = MySecondField
Me.DateReviewed = MyThirdField
Me.ReportType = MyFouthField
Me.ReviewerType = MyFifthField
Me.Reviewer = MySixthField
Me.ReviewerReportArea = MySeventhField
Me.Ownership = MyEigthField
Me.MainSection = MyNinthField
Me.TopicSection = MyTenthField
End Sub
Thank you