Syntax Error INSERT INTO!!! HELP!!

Can anyone Help

  • Yes

    Votes: 2 66.7%
  • No

    Votes: 1 33.3%

  • Total voters
    3

violentjay25

Registered User.
Local time
Today, 17:12
Joined
Feb 22, 2005
Messages
30
I need help. I have a simple form with 1 combo box and 2 text boxes. The combo box is populating from tbl_Projects. I want to select a value from this box and insert a record into a new table with data I populate in the 2 text files (Im using the combo so users cant type in values wrong and have duplicate data) My code seems simple but I keep getting a Runtime Error 3134 Syntax Error in INSERT INTO statement. Here is the code

Private Sub cmdUpdate_Click()

On Error GoTo Err_cmdUpdate_Click
DoCmd.RunSQL "insert into tbl_Updates (Date,Memo,ProjectName) " & _
"select distinct " & _
"[Forms]![frmUpdate]![txtMemo] as Memo, " & _
"[Forms]![frmUpdate]![txtDate] as Date, " & _
"[Forms]![frmUpdate]![cboProjectName] as ProjectName from tbl_Updates;"

DoCmd.GoToRecord , , acNewRec

Exit_cmdUpdate_Click:
Exit Sub

Err_cmdUpdate_Click:
MsgBox Err.Description
Resume Exit_cmdUpdate_Click

End Sub
 
vj,

I'm just assuming that you want to put the three fields from your form
into tbl_Updates. Don't know why they're not bound to a form, but ...

Code:
DoCmd.RunSQL "Insert into tbl_Updates (Date, Memo, ProjectName) " & _
                     "Values (#" & Me.txtDate & "#, '" & _
                                   Me.TextMemotxtMemo & "', '" & _
                                   Me.cboProjectName & "')"

Also, don't use "Date" and "Memo" as column names - they're reserved.

Wayne
 
Thank you

Thank you for that code. It worked like a charm. I can now stop pulling out my hair
 

Users who are viewing this thread

Back
Top Bottom