I have produced the following code to insert data from a form into a Results table. The results table has a Primary key set on the field 'Personnel' to ensure that only one record can be saved for each employee. I want to adapt this code so that if an enty already exists in the Results table this will be overwritten with the latest data. Any ideas on how or what code I should use would be greatly appreciated.
Many Thanks in Advance
Private Sub Save_Click()
alrighty... based on the fact that you're using VALUES instead of a select, I assume you're appending data one record at a time. Therefore, I would use an if statement with a DCount as criteria and run either an update, or insert statement based on the criteria. Eg:
Dim sql As String
If DCount("yourField", "yourTable", "yourField = " & yourKeyControl) Then
sql = "UPDATE yourTable SET ..." etc.
sql = "INSERT INTO yourTable (fields) ..." etc