473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I break a long single line into multiple line

How do I break the strSQL line into shorter lines? I know it's been asked here a thousand times but nothing seems to work. I keep getting "compile error: Expected: End of statement" Any recommendations for this novice would be great.

Expand|Select|Wrap|Line Numbers
  1. Sub Button10_Click()
  2. Dim strSQL As String
  3.  
  4. Set appAccess = CreateObject("Access.Application")
  5.  
  6. appAccess.Visible = False
  7.  
  8.  
  9. strSQL = "INSERT INTO [Finished Batches] ([ReleaseDate],[BatchSheetNo],[LotNumber],[BatchSize],[UOM],[BlenderNumber],[Ingr1],[Amt1],[Ing2],[Ing3],[Ing4],[Ing5],[Ing6],[Ing7],[Ing8],[Ing9],[Ing10],[Ing11],[Ing12],[Ing13],[Ing14],[Ing15],[Ing16],[Ing17],[Ing18],[Ing19],[Ing20],[Ing21],[Ing22],[Ing23],[Ing24],[Ing25],[Ing26],[Ing27],[Amt2],[Amt3],[Amt4],[Amt5],[Amt6],[Amt7],[Amt8],[Amt9],[Amt10],[Amt11],[Amt12],[Amt13],[Amt14],[Amt15],[Amt16],[Amt17],[Amt18],[Amt19],[Amt20],[Amt21],[Amt22],[Amt23],[Amt24],[Amt25],[Amt26],[Amt27],[Lot1a],[Lot2a],[Lot3a],[Lot4a],[Lot5a],[Lot6a],[Lot7a],[Lot8a],[Lot9a],[Lot10a],[Lot11a],[Lot12a],[Lot13a],[Lot14a],[Lot15a],[Lot16a],[Lot17a],[Lot18a],[Lot19a],[Lot20a],[Lot21a],[Lot22a],[Lot23a],[Lot24a],[Lot25a],[Lot26a],[Lot27a],[Amt1a],[Amt2a])" & _
  10.          "VALUES (#" & Range("G2") & "#,'" & Range("D2") & "','" & Range("B2") & "'," & Range("k1") & ",'" & Range("L1") & "','" & Range("j2") & "','" & Range("c5") & _
  11.          "'," & Range("J5") & ",'" & Range("C6") & "','" & Range("c7") & "','" & Range("c8") & "','" & Range("c9") & "','" & Range("c10") & "','" & Range("c11") & "','" & Range("c12") & _
  12.          "','" & Range("c13") & "','" & Range("C14") & "','" & Range("c15") & "','" & Range("c16") & "','" & Range("c17") & "','" & Range("c18") & "','" & Range("c19") & "','" & Range("c20") & "','" & Range("c21") & _
  13.          "','" & Range("C22") & "','" & Range("c23") & "','" & Range("c24") & "','" & Range("c25") & "','" & Range("c26") & "','" & Range("c27") & "','" & Range("c28") & "','" & Range("c29") & "','" & Range("c30") & _
  14.          "','" & Range("c31") & "'," & Range("j6") & "," & Range("j7") & "," & Range("j8") & "," & Range("j9") & "," & Range("j10") & "," & Range("j11") & "," & Range("j12") & "," & Range("j13") & "," & Range("j14") & _
  15.          "," & Range("j15") & "," & Range("j16") & "," & Range("j17") & "," & Range("j18") & "," & Range("j19") & "," & Range("j20") & "," & Range("j21") & "," & Range("j22") & "," & Range("j23") & "," & Range("j24") & _
  16.          "," & Range("j25") & "," & Range("j26") & "," & Range("j27") & "," & Range("j28") & "," & Range("j29") & "," & Range("j30") & "," & Range("j31") & ",'" & Range("k5") & "','" & Range("k6") & "','" & Range("k7") & _
  17.          "','" & Range("k8") & "','" & Range("k9") & "','" & Range("k10") & "','" & Range("k11") & "','" & Range("k12") & "','" & Range("k13") & "','" & Range("k14") & "','" & Range("k15") & "','" & Range("k16") & "','" & Range("k17") & "','" & Range("k18") & "','" & Range("k19") & "','" & Range("k20") & _
  18.          "','" & Range("k21") & "','" & Range("k22") & "','" & Range("k23") & "','" & Range("k24") & "','" & Range("k25") & "','" & Range("k26") & "','" & Range("k27") & "','" & Range("k28") & "','" & Range("k29") & "','" & Range("k30") & "','" & Range("k31") & "'," & Range("L5") & "," & Range("L6") & ")"
  19.  
  20.  
  21. With appAccess
  22.   .OpenCurrentDatabase ("C:\users\jay neuhoff\desktop\database\ss database.mdb")
  23.   Debug.Print strSQL
  24.   .DoCmd.RunSQL strSQL, dbFailOnError
  25.   .CloseCurrentDatabase
  26.  
  27. End With
  28.  
  29. Set appAccess = Nothing
  30.  MsgBox ("saved")
  31. End Sub
  32.  
Feb 28 '15 #1

✓ answered by twinnyfo

No. Line 9-10 must look like this:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO [Finished Batches] ([ReleaseDate],[BatchSheetNo],[LotNumber],[BatchSize],[UOM],[BlenderNumber],[Ingr1], " & _
  2.         "[Amt1],[Ing2],[Ing3],[Ing4],[Ing5],[Ing6],[Ing7],[Ing8],[Ing9],[Ing10],[Ing11],[Ing12],[Ing13],[Ing14],[Ing15],[Ing16],[Ing17],[Ing18],[Ing19],[Ing20],[Ing21],[Ing22],[Ing23],[Ing24],[Ing25],[Ing26],[Ing27],[Amt2],[Amt3],[Amt4],[Amt5],[Amt6],[Amt7],[Amt8],[Amt9],[Amt10],[Amt11],[Amt12],[Amt13],[Amt14],[Amt15],[Amt16],[Amt17],[Amt18],[Amt19],[Amt20],[Amt21],[Amt22],[Amt23],[Amt24],[Amt25],[Amt26],[Amt27],[Lot1a],[Lot2a],[Lot3a],[Lot4a],[Lot5a],[Lot6a],[Lot7a],[Lot8a],[Lot9a],[Lot10a],[Lot11a],[Lot12a],[Lot13a],[Lot14a],[Lot15a],[Lot16a],[Lot17a],[Lot18a],[Lot19a],[Lot20a],[Lot21a],[Lot22a],[Lot23a],[Lot24a],[Lot25a],[Lot26a],[Lot27a],[Amt1a],[Amt2a])" & _
Remember that a string, when interrupted, must be enclosed by Double Quotes.

19 1700
Luuk
1,047 Expert 1GB
Try this, it will be much more readable
Expand|Select|Wrap|Line Numbers
  1.  
  2.  secondpart = ""
  3.  strSQL = "INSERT INTO [Finished Batches] ( "
  4.  srqSQL = strSQL & "[ReleaseDate], " 
  5.  secondpart = secondpart & " #"&Range("G2")
  6.  
  7.  strsql = strsql & "BatchSheetNo], "
  8.  secondpart = secondpart & ", '" & Range("D2") & "'"
  9.  
  10.  ....etc,etc...
  11.  
  12.  strsql = strsql & "(" & secondpart & ")";
  13.  
  14.  
  15.  
Feb 28 '15 #2
Thanks, that is so much better. But I spent a lot of time trying to break down line 9 so I am still wondering if it is even possible, and if its not, why?
Mar 1 '15 #3
Luuk
1,047 Expert 1GB
It should be possible, like this
Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT " & _ 
  2.   "INTO " & _
  3.       "[Finished Batches] (" & _
  4.           "[ReleaseDate]," & _
  5.           "[BatchSheetNo]," & _ 
  6. etc,etc...
  7.           "[Amt1a]," & _
  8.           "[Amt2a])"
  9.  
Mar 1 '15 #4
Luuk
1,047 Expert 1GB
But note the explanation here:
https://msdn.microsoft.com/en-us/lib.../gg278750.aspx
•A line contains too many characters. You can create a longer logical line by joining physical lines with a line-continuation character, a space followed by an underscore ( _). Up to 25 physical lines can be joined with line-continuation characters to form a single logical line, or 24 consecutive line-continuation characters. Thus, a logical line could potentially contain a total of 10,230 characters.
Mar 1 '15 #5
My problem is that the underscore causes a compile error. Give it a try. :)
Mar 2 '15 #6
twinnyfo
3,653 Expert Mod 2GB
Ineedhlpplz,

Luuk's explanation in Post #5 is correct.

However, there is nothing that precludes you from breaking the creation of the creation of your string into multiple segments. E.G.:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO [Finished Batches] " & _ etc.
  2.  
  3. strSQL = strSQL & " VALUES (#" & Range("G2") & "#," & _ etc.
You can link as many of these partial segments together that you want.

This method may also help you trouble shoot if there are problems with your query.
Mar 2 '15 #7
NeoPa
32,556 Expert Mod 16PB
INeedHlpPlz:
My problem is that the underscore causes a compile error. Give it a try. :)
I hate to contradict, but that's simply not true. It may be true that your code fails to compile after you've added undescores, but if so then you are not doing it correctly.

What is the compile error you're getting? That would be a good place to start. Remember that the explanation is quite explicit about ensuring there is a space before the underscore. If you don't include the space then it won't be recognised as a line-continuation. Also that only 24 can be used in a single logical line.
Mar 2 '15 #8
I did provide the compile error in my original post because I thought it would be a good place to start. Try using a space underscore in line 9. It should work. But doesn't. I've tried it 100 ways. see below
Expand|Select|Wrap|Line Numbers
  1. Sub Button10_Click()
  2. Dim strSQL As String
  3.  
  4. Set appAccess = CreateObject("Access.Application")
  5.  
  6. appAccess.Visible = False
  7.  
  8.  
  9. strSQL = "INSERT INTO [Finished Batches] ([ReleaseDate],[BatchSheetNo],[LotNumber],[BatchSize],[UOM],[BlenderNumber],[Ingr1], _
  10.         [Amt1],[Ing2],[Ing3],[Ing4],[Ing5],[Ing6],[Ing7],[Ing8],[Ing9],[Ing10],[Ing11],[Ing12],[Ing13],[Ing14],[Ing15],[Ing16],[Ing17],[Ing18],[Ing19],[Ing20],[Ing21],[Ing22],[Ing23],[Ing24],[Ing25],[Ing26],[Ing27],[Amt2],[Amt3],[Amt4],[Amt5],[Amt6],[Amt7],[Amt8],[Amt9],[Amt10],[Amt11],[Amt12],[Amt13],[Amt14],[Amt15],[Amt16],[Amt17],[Amt18],[Amt19],[Amt20],[Amt21],[Amt22],[Amt23],[Amt24],[Amt25],[Amt26],[Amt27],[Lot1a],[Lot2a],[Lot3a],[Lot4a],[Lot5a],[Lot6a],[Lot7a],[Lot8a],[Lot9a],[Lot10a],[Lot11a],[Lot12a],[Lot13a],[Lot14a],[Lot15a],[Lot16a],[Lot17a],[Lot18a],[Lot19a],[Lot20a],[Lot21a],[Lot22a],[Lot23a],[Lot24a],[Lot25a],[Lot26a],[Lot27a],[Amt1a],[Amt2a])" & _
  11.          "VALUES (#" & Range("G2") & "#,'" & Range("D2") & "','" & Range("B2") & "'," & Range("k1") & ",'" & Range("L1") & "','" & Range("j2") & "','" & Range("c5") & _
  12.          "'," & Range("J5") & ",'" & Range("C6") & "','" & Range("c7") & "','" & Range("c8") & "','" & Range("c9") & "','" & Range("c10") & "','" & Range("c11") & "','" & Range("c12") & _
  13.          "','" & Range("c13") & "','" & Range("C14") & "','" & Range("c15") & "','" & Range("c16") & "','" & Range("c17") & "','" & Range("c18") & "','" & Range("c19") & "','" & Range("c20") & "','" & Range("c21") & _
  14.          "','" & Range("C22") & "','" & Range("c23") & "','" & Range("c24") & "','" & Range("c25") & "','" & Range("c26") & "','" & Range("c27") & "','" & Range("c28") & "','" & Range("c29") & "','" & Range("c30") & _
  15.          "','" & Range("c31") & "'," & Range("j6") & "," & Range("j7") & "," & Range("j8") & "," & Range("j9") & "," & Range("j10") & "," & Range("j11") & "," & Range("j12") & "," & Range("j13") & "," & Range("j14") & _
  16.          "," & Range("j15") & "," & Range("j16") & "," & Range("j17") & "," & Range("j18") & "," & Range("j19") & "," & Range("j20") & "," & Range("j21") & "," & Range("j22") & "," & Range("j23") & "," & Range("j24") & _
  17.          "," & Range("j25") & "," & Range("j26") & "," & Range("j27") & "," & Range("j28") & "," & Range("j29") & "," & Range("j30") & "," & Range("j31") & ",'" & Range("k5") & "','" & Range("k6") & "','" & Range("k7") & _
  18.          "','" & Range("k8") & "','" & Range("k9") & "','" & Range("k10") & "','" & Range("k11") & "','" & Range("k12") & "','" & Range("k13") & "','" & Range("k14") & "','" & Range("k15") & "','" & Range("k16") & "','" & Range("k17") & "','" & Range("k18") & "','" & Range("k19") & "','" & Range("k20") & _
  19.          "','" & Range("k21") & "','" & Range("k22") & "','" & Range("k23") & "','" & Range("k24") & "','" & Range("k25") & "','" & Range("k26") & "','" & Range("k27") & "','" & Range("k28") & "','" & Range("k29") & "','" & Range("k30") & "','" & Range("k31") & "'," & Range("L5") & "," & Range("L6") & ")"
  20.  
  21.  
  22. With appAccess
  23.   .OpenCurrentDatabase ("C:\users\jay neuhoff\desktop\database\ss database.mdb")
  24.   Debug.Print strSQL
  25.   .DoCmd.RunSQL strSQL, dbFailOnError
  26.   .CloseCurrentDatabase
  27.  
  28. End With
  29.  
  30. Set appAccess = Nothing
  31.  MsgBox ("saved")
  32. End Sub
Mar 2 '15 #9
I just want to use a space and underscore in line 9. Is it possible? How?
Mar 2 '15 #10
twinnyfo
3,653 Expert Mod 2GB
No. Line 9-10 must look like this:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO [Finished Batches] ([ReleaseDate],[BatchSheetNo],[LotNumber],[BatchSize],[UOM],[BlenderNumber],[Ingr1], " & _
  2.         "[Amt1],[Ing2],[Ing3],[Ing4],[Ing5],[Ing6],[Ing7],[Ing8],[Ing9],[Ing10],[Ing11],[Ing12],[Ing13],[Ing14],[Ing15],[Ing16],[Ing17],[Ing18],[Ing19],[Ing20],[Ing21],[Ing22],[Ing23],[Ing24],[Ing25],[Ing26],[Ing27],[Amt2],[Amt3],[Amt4],[Amt5],[Amt6],[Amt7],[Amt8],[Amt9],[Amt10],[Amt11],[Amt12],[Amt13],[Amt14],[Amt15],[Amt16],[Amt17],[Amt18],[Amt19],[Amt20],[Amt21],[Amt22],[Amt23],[Amt24],[Amt25],[Amt26],[Amt27],[Lot1a],[Lot2a],[Lot3a],[Lot4a],[Lot5a],[Lot6a],[Lot7a],[Lot8a],[Lot9a],[Lot10a],[Lot11a],[Lot12a],[Lot13a],[Lot14a],[Lot15a],[Lot16a],[Lot17a],[Lot18a],[Lot19a],[Lot20a],[Lot21a],[Lot22a],[Lot23a],[Lot24a],[Lot25a],[Lot26a],[Lot27a],[Amt1a],[Amt2a])" & _
Remember that a string, when interrupted, must be enclosed by Double Quotes.
Mar 2 '15 #11
twinnyfo
3,653 Expert Mod 2GB
However, just looking at the width of your table and the number of fields, something tells me that your database is not fully normalized (see this topic for help: Database Normalization).

However, assuming that all your fields and data is necessary as is, the tips above should help you find a solution.
Mar 2 '15 #12
Thank you! I tried it so many ways but never put double quotes starting the new line. I'll read that info about normalization. Thanks to everyone!
Mar 2 '15 #13
twinnyfo
3,653 Expert Mod 2GB
Great! I'm glad I could be of some service!
Mar 2 '15 #14
NeoPa
32,556 Expert Mod 16PB
Just in case you're not sure why the double-quotes made the difference here - the continuation character must be between determinable sub-statements within a line. A string literal is not complete until it hits a terminating (single) double-quote character. Anything within a string literal is, by definition, within a sub-statement.

If you're curious as to why that would be the case then simply consider how complicated it would be to express certain values within a string if such character combinations were always treated as special characters instead of what you write in the string.
Mar 2 '15 #15
Thanks NeoPa, that makes sense.
Mar 3 '15 #16
twinnyfo
3,653 Expert Mod 2GB
(whisper) Just so you know, NeoPa knows EVERYTHING!

:-)
Mar 3 '15 #17
NeoPa
32,556 Expert Mod 16PB
More than happy to help. TwinnyFo did all the heavy lifting here. I just popped in to add a little snippet in the hope that it helps.
Mar 3 '15 #18
Luuk
1,047 Expert 1GB
nah, he was just repeating what I told to Ineedhelpplz in the first place....

;)
Mar 7 '15 #19
NeoPa
32,556 Expert Mod 16PB
In a way you're right Luuk. Often in life though, it's not all about the answer - but much about leading someone towards being able to understand and work with that info.

Your contribution was helpful and important but TwinnyFo still did the heavy lifting in this case. He stuck with it and made it happen ;-)

Never worry that your original perfect answer is overlooked though. Most of the benefit that this site gives is to those users who look but never post. For them your contribution will surely prove very helpful for a long time to come.
Mar 8 '15 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jon LaRosa | last post by:
I'm am trying to remove multiple line breaks ("\n"). Here's my code: $imageStr = trim($_POST); $imageStr = str_replace("\n\n", "\n", $imageStr); ---------- $_POST is a textarea field, and...
8
by: MrTrix | last post by:
Hello: I'm having a problem formulating the code to execute a multiple line command. I'm trying to execute something like: set rowcount 100000 declare @rowct int select @rowct = 1 while...
5
by: SA Dev | last post by:
Hi, I just finished writing something to make a help file for a Pocket PC device. The Pocket PC device allows not really showing the .HTM file as a long single file, but instead uses a tag to...
4
by: Carolyn Marenger | last post by:
Hey everyone, I am looking for your thoughts and opinions. Is it preferable to have one css file containing all the style information or break it up into multiple imported files for different...
8
by: Frost | last post by:
Hi All, I am a newbie i have written a c program on unix for line by line comparison for two files now could some one help on how i could do word by word comparison in case both lines have the...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
17
by: kevgibbo | last post by:
Hi, I'm currently having a problem where a long URL or a line of text with no spaces will break the design of a webpage, http:// blog.seoptimise.com/2007/01/how-to-add-delicious-and-digg-blog-...
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
1
by: stewc | last post by:
Hi I am using this line of code var str = (<r><!]></r>).toString(); to convert a multiple line string to a single line so I can remove the line breaks It works great in Firefox but...
4
by: franc sutherland | last post by:
Hello, Is it possible to make multiple line notes in the VB editor? I know about using the apostrophe ' to make a single line note. Is there a version for making multiple lined notes? If...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.