Hello,
I have a problem using sql in an Access (2016) module. I’m completely lost trying to elaborate a sql statement like INSERT INTO … VALUES.
Here is the routine :
Private Sub Nom_AfterUpdate()
Dim CeJour As Date
CeJour = Format(Date, "dd/mm/yyyy")
'
Ajout = Me.Controls![N°].Value
'
'Following sql statement works !
'StrSQL = "INSERT INTO tbl_data (Id) VALUES ('" & Ajout & "' );"
'
' This one doesn't
'
StrSQL = "INSERT INTO tbl_data (Id,Date_1er_Contact) VALUES ('" & Ajout & "', Cejour );"
'
'
DoCmd.SetWarnings False
DoCmd.RunSQL StrSQL
DoCmd.SetWarnings True
'
End Sub
The first sql is running perfectly :
StrSQL = "INSERT INTO tbl_data (Id) VALUES ('" & Ajout & "' );"
But I have two values to add to a table. So I try to have the correct syntax. I tried all possibility but without success. The ‘best’ statement leads to popups asking for values …
StrSQL = "INSERT INTO tbl_data (Id,Date_1er_Contact) VALUES ('" & Ajout & "', Cejour );"
‘Ajout’ is a number taken from a field in a form. Supposed to be added in a numerical field.
‘CeJour’ is the current date. Supposed to be added in a date formated field.
Could you please help ? I surfed on the web for half a night and maybe not far from a whole day to find the correct syntax....
Many thanks in advance.