Hi all,
I am having a slight issue. I am trying to create an Insert Into SQL statement, and keep getting errors. I have managed to insert into my table using a recordset, but ideally would like to use an SQL statement. My working recordset statement is as follows:
The SQL statement I have been trying to use is as follows:
I must have the syntax wrong in the above statement, but after many hours and iterations I am no closer to having it working. I have tried with and without ## around the date txt box, and have tried using format() but to no avail. It would be great if someone could point me in the direction of my errors.
Many thanks
I am having a slight issue. I am trying to create an Insert Into SQL statement, and keep getting errors. I have managed to insert into my table using a recordset, but ideally would like to use an SQL statement. My working recordset statement is as follows:
Code:
Private Sub cmd_AddDF_Click()
Dim MyDB As DAO.Database, MyRS As DAO.Recordset
Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecordset("tblDemandForcast", dbOpenDynaset)
On Error GoTo Err_cmd_AddDF_Click
If Not IsNull(DLookup("[GasDay]", _
"[tblDemandForcast]", _
"[GasDay]=#" & Me!txtRepDate & "#")) Then
MsgBox("Record already Exists.")
exit sub
else
With MyRS
.AddNew
![Gasday] = Me![txtRepDate]
![D] = Me![txtD0]
![D1] = Me![txtD1]
![D2] = Me![txtD2]
![D3] = Me![txtD3]
![D4] = Me![txtD4]
![D5] = Me![txtD5]
![D6] = Me![txtD6]
.Update
End With
MyRS.Close
End If
Exit_cmd_AddDF_Click:
Exit Sub
Err_cmd_AddDF_Click:
MsgBox Err.Description
Resume Exit_cmd_AddDF_Click
End Sub
The SQL statement I have been trying to use is as follows:
Code:
DoCmd.RunSQL "INSERT INTO [tblDemandForcast] " & _
"([GasDay] & ", " & [D] & ", " & [D1] & ", " & [D2] & ", " & [D3] & ", " & [D4] & ", " & [D5] & ", " & [D6]) " & _
"VALUES ('" & Me.txtRepDate & "','" & Me.txtD0 & "'," & Me.txtD1 & ", '" & Me.txtD2 & "','" & Me.txtD3 & "','" & Me.txtD4 & "','" & Me.txtD5 & "','" & Me.txtD6 & "')"
I must have the syntax wrong in the above statement, but after many hours and iterations I am no closer to having it working. I have tried with and without ## around the date txt box, and have tried using format() but to no avail. It would be great if someone could point me in the direction of my errors.
Many thanks