Can anyone tell me why this sql won't work?
I'm trying to append to a table using values from a form. this is the code;
Dim strSQL As String
strSQL = "INSERT INTO tblOTStatement (caseNum,officerPK,otSourcePK,hours,date) VALUES (""" & cmboReason & """," & cmboSurname & "," & cmboSource & "," & txtHours & ",#" & Format(txtDate, "mm/dd/yyyy") & "#);"
Debug.Print strSQL
DoCmd.RunSQL (strSQL)
By using debug.print I can examine strSQL's value, which in my test is;
INSERT INTO tblOTStatement (caseNum,officerPK,otSourcePK,hours,date) VALUES ("testing",13,7,23,#08/19/2004#);
I can't see anything wrong with it. I've checked that the various columns are getting the correct type of value. The value shown as "testing", I've tried as 'testing' and I've tried a formatted and non-formatted date.
The error that I get is "Run-Time error 3134, Syntax error in Insert into statement"
The only thing that I can think of that may be causing problems is the fact that the table has an autonumber primary key, which is not being addressed in my SQL. Is this an issue, I was under the impression that access would automatically allocate a value. The table has another three columns (including the primary key) which are not addressed in this query. None are required (other than the PK obviously).
I'm trying to append to a table using values from a form. this is the code;
Dim strSQL As String
strSQL = "INSERT INTO tblOTStatement (caseNum,officerPK,otSourcePK,hours,date) VALUES (""" & cmboReason & """," & cmboSurname & "," & cmboSource & "," & txtHours & ",#" & Format(txtDate, "mm/dd/yyyy") & "#);"
Debug.Print strSQL
DoCmd.RunSQL (strSQL)
By using debug.print I can examine strSQL's value, which in my test is;
INSERT INTO tblOTStatement (caseNum,officerPK,otSourcePK,hours,date) VALUES ("testing",13,7,23,#08/19/2004#);
I can't see anything wrong with it. I've checked that the various columns are getting the correct type of value. The value shown as "testing", I've tried as 'testing' and I've tried a formatted and non-formatted date.
The error that I get is "Run-Time error 3134, Syntax error in Insert into statement"
The only thing that I can think of that may be causing problems is the fact that the table has an autonumber primary key, which is not being addressed in my SQL. Is this an issue, I was under the impression that access would automatically allocate a value. The table has another three columns (including the primary key) which are not addressed in this query. None are required (other than the PK obviously).