mikemck7
Technical User
- Dec 17, 2003
- 38
Hello,
I have two tables, CLIENTS and TASKS that are linked by a field named CID in a one to many relationship. The Task records are displayed as a subform.
The main form contains the command button cmdAddTask with the code below in its Click event. When the button is clicked, a new record containing the client's id and the current date and time (both as string data type) is to be inserted into the task table.
When I run the concatenated INSERT statement I get the syntax error: "Missing operator in Query Expression".
If I try to run it directly I have to manually enter parameter values for txtSdate and txtStime, (but not txtCid) before the record will be inserted.
Why are niether of these methods working?
Thanks,
Mike
I have two tables, CLIENTS and TASKS that are linked by a field named CID in a one to many relationship. The Task records are displayed as a subform.
The main form contains the command button cmdAddTask with the code below in its Click event. When the button is clicked, a new record containing the client's id and the current date and time (both as string data type) is to be inserted into the task table.
Code:
Private Sub CmdAddTask_Click()
Dim txtCid As String, txtSdate As String, txtStime As String, txtNow As String
txtNow = Now
txtCid = Forms!clients!cid.Value
txtSdate = Trim(Left(txtNow, InStr(txtNow, " ")))
txtStime = Mid(txtNow, InStr(txtNow, " ") + 1)
Dim db As Database
Dim lsql As String
Set db = CurrentDb()
lsql = "INSERT into tasks (cid, sdate, stime) VALUES (" & txtCid & ", " & txtSdate & ", " & txtStime & ")"
DoCmd.RunSQL lsql
'or
'DoCmd.RunSQL "INSERT into tasks (cid, sdate, stime) VALUES (txtCid, txtSdate, txtStime)"
Tasks_subform.Requery
End Sub
When I run the concatenated INSERT statement I get the syntax error: "Missing operator in Query Expression".
If I try to run it directly I have to manually enter parameter values for txtSdate and txtStime, (but not txtCid) before the record will be inserted.
Why are niether of these methods working?
Thanks,
Mike