I have a Form which updates the Customer table and views the Invoicing done to each customer. In the same form I want to be able to add new records but using the vba as follows:
Private Sub btnAddRecord_Click()
Dim tblClientesausensi As DAO.Recordset
Set rstClientesausensi = CurrentDb.OpenRecordset("SELECT * FROM [Clientesausensi]")
rstClientesausensi.AddNew
rstClientesausensi![IdCliente] = Me.IdCliente.Value
rstClientesausensi![Empresa] = Me.Empresa.Value
rstClientesausensi![Rut] = Me.Rut.Value
rstClientesausensi![Giro] = Me.Giro.Value
rstClientesausensi![Dirección] = Me.Dirección.Value
rstClientesausensi![Comuna] = Me.Comuna.Value
rstClientesausensi![Ciudad] = Me.Ciudad.Value
rstClientesausensi![Telefono] = Me.Telefono.Value
rstClientesausensi![Fax] = Me.Fax.Value
rstClientesausensi![Email] = Me.Email.Value
rstClientesausensi.Update
rstClientesausensi.Close
Set rstClientesausensi = Nothing
DoCmd.Close
End Sub
However, it complaints about duplicate records(error 3022: it says that it would create duplicate records if allowed to process, so it advice to remove the key value from the table, which I do not think is the right approach), which I imagine is the code I have to put prior to the one that is her correct ??. Could anybody guide me on this ?.
Thank you so much.