Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    41

    Unanswered: Line Break - Newbie

    Hey,

    Just wondering how I can break the following line of code:

    DoCmd.RunSQL "INSERT INTO tblmain (Trainer, Date1, Week1, A1_1, Comments1, A2_1, Comments2, A3_1, Comments3, topic4_1, Ans4_1, Com4_1, topic4_2, Ans4_2, Com4_2, topic4_3, Ans4_3, Com4_3, topic4_4, Ans4_4, Com4_4, topic4_5, Ans4_5, Com4_5, topic4_6, Ans4_6, Com4_6, topic4_7, Ans4_7, Com4_7, topic4_8, Ans4_8, Com4_8, q5fav1, q5fav2, q5fav3, q5fav4, q5lfav1, q5lfav2, q5lfav3, q5lfav4) Values (" & Forms!frmmain2!cbotrainer & ", #" & Forms!frmmain2!txtDate & "#," & Forms!frmmain2!cboweek & ", " & Forms!frmmain2!cboans1 & ", '" & Forms!frmmain2!Comments1 & "', " & Forms!frmmain2!cboans2 & ", '" & Forms!frmmain2!Comments2 & "', " & Forms!frmmain2!cboans3 & ", '" & Forms!frmmain2!Comments3 & "')"

    I tried space + underscore then hit enter and that did work. I was looking to break the line before the word "Values".

    Do anyone know how I can do this?

    Thanks

  2. #2
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    put your sql string in to a string variable. that way you can divide it several lines without problem.
    Code:
      Dim  SqlStr as String
      SqlStr = "INSERT INTO tblmain (Trainer, Date1, Week1, A1_1, Comments1, A2_1, Comments2, A3_1, Comments3, topic4_1, Ans4_1, Com4_1, topic4_2, Ans4_2, Com4_2, topic4_3, Ans4_3, Com4_3, topic4_4, Ans4_4, Com4_4, topic4_5, Ans4_5, Com4_5, topic4_6, Ans4_6, Com4_6, topic4_7, Ans4_7, Com4_7, topic4_8, Ans4_8, Com4_8, q5fav1, q5fav2, q5fav3, q5fav4, q5lfav1, q5lfav2, q5lfav3, q5lfav4)"
      SqlStr = SqlStr + " Values (" & Forms!frmmain2!cbotrainer & ", #" & Forms!frmmain2!txtDate & "#," & Forms!frmmain2!cboweek & ", " & Forms!frmmain2!cboans1 & ", '" & Forms!frmmain2!Comments1 & "', " & Forms!frmmain2!cboans2 & ", '" & Forms!frmmain2!Comments2 & "', " & Forms!frmmain2!cboans3 & ", '" & Forms!frmmain2!Comments3 & "')"
      DoCmd.RunSQL (SqlStr)
    ghozy.

  3. #3
    Join Date
    Apr 2003
    Location
    Alabama, USA
    Posts
    154
    Quote Originally Posted by justlearning200
    Hey,

    Just wondering how I can break the following line of code:

    DoCmd.RunSQL "INSERT INTO tblmain (Trainer, Date1, Week1, A1_1, Comments1, A2_1, Comments2, A3_1, Comments3, topic4_1, Ans4_1, Com4_1, topic4_2, Ans4_2, Com4_2, topic4_3, Ans4_3, Com4_3, topic4_4, Ans4_4, Com4_4, topic4_5, Ans4_5, Com4_5, topic4_6, Ans4_6, Com4_6, topic4_7, Ans4_7, Com4_7, topic4_8, Ans4_8, Com4_8, q5fav1, q5fav2, q5fav3, q5fav4, q5lfav1, q5lfav2, q5lfav3, q5lfav4) Values (" & Forms!frmmain2!cbotrainer & ", #" & Forms!frmmain2!txtDate & "#," & Forms!frmmain2!cboweek & ", " & Forms!frmmain2!cboans1 & ", '" & Forms!frmmain2!Comments1 & "', " & Forms!frmmain2!cboans2 & ", '" & Forms!frmmain2!Comments2 & "', " & Forms!frmmain2!cboans3 & ", '" & Forms!frmmain2!Comments3 & "')"

    I tried space + underscore then hit enter and that did work. I was looking to break the line before the word "Values".

    Do anyone know how I can do this?

    Thanks
    Do you mean so that it'll fit on a page in your code screen? If so then do this

    DoCmd.RunSQL "INSERT INTO tblmain (Trainer, Date1, Week1, A1_1, Comments1, A2_1, Comments2, A3_1, Comments3, topic4_1, Ans4_1, Com4_1, topic4_2, Ans4_2, Com4_2, topic4_3, Ans4_3, Com4_3, topic4_4, Ans4_4, Com4_4, topic4_5, Ans4_5, Com4_5, topic4_6, Ans4_6, Com4_6, topic4_7, Ans4_7, Com4_7, topic4_8, Ans4_8, Com4_8, q5fav1, q5fav2, q5fav3, q5fav4, q5lfav1, q5lfav2, q5lfav3, q5lfav4) " & _
    "Values (" & Forms!frmmain2!cbotrainer & ", #" & Forms!frmmain2!txtDate & "#," & Forms!frmmain2!cboweek & ", " & Forms!frmmain2!cboans1 & ", '" & Forms!frmmain2!Comments1 & "', " & Forms!frmmain2!cboans2 & ", '" & Forms!frmmain2!Comments2 & "', " & Forms!frmmain2!cboans3 & ", '" & Forms!frmmain2!Comments3 & "')"

    When you want to wrap code to the next line you can use & _ and hit enter to return the code to the next line

    e.g.
    Code:
    'Example 1
    msgbox "The name of this form is " & _
    me.name
    
    'Example 2
    msgbox me.name & _
    "is the name of this form."
    
    'Example 3
    msgbox me.name & "is the name " & _
    "of this form."
    Note that the second and third example will give the same results but because you are splitting text you need to "close" if off first, then use & _ and continue the text. Please note that you have to include that extra space after "the name ".

    Hope this is what you are trying to do.
    http://AccessDB.Info

    You live and learn. At any rate, you live. - Douglas Adams

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •