Hi
I am receiving the error above when I try to execute the code below. I have checked the fields in the code as well as the table and I can't see what I am missing. The tblMeasure table which is the subform have the following fields:
- MUserLoginID - Number
- MainMeasureID - AutoNumber - Primary Key
- MeasureName - Text
- MPositonName - Text
- MeasureScore - Number
- MeasureWeight - Number
- MeasureTotal - Number
- MeasureDesc - Memo
- MStaffApraisedID - Number
The UserDeatils table which is the main form have the following fields:
- StaffID - Number
- StaffName - Text
- DepartmentName - Text
- StaffPosition - Text
- StaffGrade - Text
- StaffBDate - Date
- StaffEDate - Date
- StaffApraisedID - AutoNumber - Primary Key
The link between the two forms are StaffApraisedID to MStaffApraisedID then StaffID to MUserLoginID then StaffPosition to MPositonName. When I select a member and click the Duplicate button I received the error above. The area highlighted in red is where it errors out.
I will really appreciate any help at this time as I am not sure what to do at this point. The code is attached below
Thanks.
Nika
Code:
Private Sub cmdDuplicateData_Click()
On Error GoTo Err_cmdDuplicateData_Click
Dim OldStaffID As Integer, NewStaffID As Integer
OldStaffID = Me.StaffApraisedID
'Add new record to end of Recodset Object
With Me.RecordsetClone
.AddNew
!StaffName = Me!StaffName
!DepartmentName = Me!DepartmentName
!StaffPosition = Me!StaffPosition
!StaffBDate = Me!StaffBDate
!StaffEDate = Me!StaffEDate
!StaffID = Me!StaffID
!StaffGrade = Me!StaffGrade
NewStaffID = !StaffApraisedID
.Update
End With
CurrentDb.Execute "INSERT INTO tblMeasure(MainMeasureID, MUserLoginID, MStaffApraisedID, MeasureName, MPositonName, MeasureScore, MeasureWeight, MeasureTotal, MeasureDesc)" & _
"SELECT MainMeasureID, MUserLoginID, MStaffApraisedID, MeasureName, MPositonName, MeasureScore, MeasureWeight, MeasureTotal, MeasureDesc, " & NewStaffID & " AS NewStaffID " & _
"FROM tblMeasure " & _
"WHERE MStaffApraisedID =" & OldStaffID & ";"
DoCmd.GoToRecord , , acLast
Exit_cmdDuplicateData_Click:
Exit Sub
Err_cmdDuplicateData_Click:
MsgBox Error$
Resume Exit_cmdDuplicateData_Click:
End Sub