Good Afternoon,
I have been developing a form that will allow me to input, edit and delete data in a table.
I have the input, delete, clear, and close command buttons working ok, but I am having trouble getting the edit function to work.
What happens is that I highlight the line in the table (shown on the form as a sub form) click the edit command button, and the field are populated with the current data. I then edit the field that I want, and the add, button, changes to Update. When I go to update I keep getting an error message "Cannot update 'ID'; field not updatable.
Below is the code I am using, when I go to the debug the arrow points to the "WHERE ID=" line.
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtID.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSER INTO tbllessonslearned(ID, Aircraft, TailNumber, Day, Classification, AddedBy, LessonsLearned) " & _
" VALUES(" & Me.txtID & ",'" & Me.cboAircraft & "','" & _
Me.txtTailNumber & "','" & Me.txtDay & "','" & Me.cboClassification & "','" & Me.txtAddedBy & "','" & Me.txtLessonsLearned & "')'"
Else
'otherwise (Tag of txtID store the ID of tbllessonslearned to be modified)
CurrentDb.Execute "UPDATE tbllessonslearned " & _
" SET ID=" & Me.txtID & _
", Aircraft='" & Me.cboAircraft & "'" & _
", TailNumber='" & Me.txtTailNumber & "'" & _
", Day='" & Me.txtDay & "'" & _
", Classification='" & Me.cboClassification & "'" & _
", AddedBy='" & Me.txtAddedBy & "'" & _
", LessonsLearned='" & Me.txtLessonsLearned & "'" & _
" WHERE ID=" & Me.txtID.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmlessonslearnedsub.Form.Requery
End Sub
Any assistance is finding where I have gone wrong would be most appreciated.
I have been developing a form that will allow me to input, edit and delete data in a table.
I have the input, delete, clear, and close command buttons working ok, but I am having trouble getting the edit function to work.
What happens is that I highlight the line in the table (shown on the form as a sub form) click the edit command button, and the field are populated with the current data. I then edit the field that I want, and the add, button, changes to Update. When I go to update I keep getting an error message "Cannot update 'ID'; field not updatable.
Below is the code I am using, when I go to the debug the arrow points to the "WHERE ID=" line.
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtID.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSER INTO tbllessonslearned(ID, Aircraft, TailNumber, Day, Classification, AddedBy, LessonsLearned) " & _
" VALUES(" & Me.txtID & ",'" & Me.cboAircraft & "','" & _
Me.txtTailNumber & "','" & Me.txtDay & "','" & Me.cboClassification & "','" & Me.txtAddedBy & "','" & Me.txtLessonsLearned & "')'"
Else
'otherwise (Tag of txtID store the ID of tbllessonslearned to be modified)
CurrentDb.Execute "UPDATE tbllessonslearned " & _
" SET ID=" & Me.txtID & _
", Aircraft='" & Me.cboAircraft & "'" & _
", TailNumber='" & Me.txtTailNumber & "'" & _
", Day='" & Me.txtDay & "'" & _
", Classification='" & Me.cboClassification & "'" & _
", AddedBy='" & Me.txtAddedBy & "'" & _
", LessonsLearned='" & Me.txtLessonsLearned & "'" & _
" WHERE ID=" & Me.txtID.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmlessonslearnedsub.Form.Requery
End Sub
Any assistance is finding where I have gone wrong would be most appreciated.