Insert Into's Where Clause

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelesh kumar
    New Member
    • Mar 2007
    • 44

    #1

    Insert Into's Where Clause

    Code:
    DoCmd.RunSQL "Insert into Table2 (question, option1, option2, " & _
    "option3,option4) Values('" & Me!question.Value & "','" & Me!option1.Value & _
    "','" & Me!option2.Value & "','" & Me!option3.Value & "','" & Me!option4.Value & _
    "') WHERE  traineeans.Value  <>'" & Me!answer.Value & "'"
    this is my statement.
    if where statement is not there then my code working
    in where statement traineeans is textbox in the form.answer is textbox.answer has a control source which is a feld in the table.
    how to write the insert into where stsement
    please help me
    Last edited by Rabbit; Apr 9 '07, 03:13 PM. Reason: [Code] Tags and Formatting
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Originally posted by neelesh kumar
    Code:
    DoCmd.RunSQL "Insert into Table2 (question, option1, option2, " & _
    "option3,option4) Values('" & Me!question.Value & "','" & Me!option1.Value & _
    "','" & Me!option2.Value & "','" & Me!option3.Value & "','" & Me!option4.Value & _
    "') WHERE  traineeans.Value  <>'" & Me!answer.Value & "'"
    this is my statement.
    if where statement is not there then my code working
    in where statement traineeans is textbox in the form.answer is textbox.answer has a control source which is a feld in the table.
    how to write the insert into where stsement
    please help me
    As far as I know, Insert Into ... Values () doesn't have a Where Clause. You can use a Where Clause using an Insert Into ... Select ... From ... Where.

    In your case, you won't be able to use that so you'll have to use an if statement to take care of your what you want your Where to do.

    Comment

    • maxamis4
      Recognized Expert Contributor
      • Jan 2007
      • 295

      #3
      Code:
      DoCmd.RunSQL "INSERT INTO Table2 (question, option1, option2, option3,option4) " _
      & " SELECT '" & Me!question.Value & "','" & Me!option1.Value & "', '" & Me!option2.Value & "','" & Me!option3.Value & "','" & Me!option4.Value &"'" _
      & " WHERE  (traineeans.Value)  <>'" & Me!answer.Value & "'"
      I might have missed something somewhere in there, but the format of the insert statement is correct. When doing an expression inside an insert statement you need select the criteria you need and then delcare the conditions of the criteria.

      good luck

      Comment

      Working...