Error 3075 When Appending Form Data to Table

D

DevDaniel

The user enters data in a form (an issue log) and clicks OK. The data should
be appended to Tables!tblComments, but I get an error: "Run-time error
'3075': Syntax error (missing operator) in query expression 'Enter comments
here.'.

Any help would be appreciated.

Note: The form is unbound. The comment field is a memo field.

The code:

Private Sub cmdACOK_Click()

Dim strSQLAddComment As String

strSQLAddComment = "INSERT INTO tblComments ( IssueID, UserID, CommentTime,
Comment, IsResolved )" & _
"SELECT " & Me.txtACIssueID.Value & ", " & Me.txtACUserID.Value & ", #"
& Me.txtACCommentTime.Value & "#, " & Me.txtACComment.Value & ", " &
Me.chkACIsResolved.Value & ";"

DoCmd.RunSQL strSQLAddComment

End Sub
 
D

Douglas J. Steele

And put parentheses before and after the list of values.

strSQLAddComment = "INSERT INTO tblComments ( IssueID, UserID, " & _
"CommentTime, Comment, IsResolved )" & _
"VALUES(" & Me.txtACIssueID.Value & ", " & Me.txtACUserID.Value & _
", #" & Me.txtACCommentTime.Value & "#, " & Me.txtACComment.Value & _
", " & Me.chkACIsResolved.Value & ")"

Assuming that Comment is a text field, you'll need quotes around it:

strSQLAddComment = "INSERT INTO tblComments ( IssueID, UserID, " & _
"CommentTime, Comment, IsResolved )" & _
"VALUES(" & Me.txtACIssueID.Value & ", " & Me.txtACUserID.Value & _
", #" & Me.txtACCommentTime.Value & "#, '" & Me.txtACComment.Value & _
"', " & Me.chkACIsResolved.Value & ")"

or

strSQLAddComment = "INSERT INTO tblComments ( IssueID, UserID, " & _
"CommentTime, Comment, IsResolved )" & _
"VALUES(" & Me.txtACIssueID.Value & ", " & Me.txtACUserID.Value & _
", #" & Me.txtACCommentTime.Value & "#, " & Chr$(34) & _
Me.txtACComment.Value & Chr$(34) & ", " & Me.chkACIsResolved.Value & ")"

(If the comments can contain apostrophes, you need the second syntax.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top