Excel VBA compile error

I have this sql statement in Excel VBA and I can't figure out what the problem here, VBA keep complain the with this error compile error;expected expression. this was working fine but it sudden stop working.
VBA complain on the begining of , ' " & dt2 & " '} ) ) " .....

Thanks
.CommandText = Array( _
        "SELECT RepairOrders.ROustNo, RepairOrders.ROCustName, RepairOrders.RODate, RepairOrders.ROMake, RepairOrders.RONo, RODetails.ROItemDesc, RODetails.RONo" & Chr(13) & "" & Chr(10) & "FROM AYS_amdj.dbo.RepairOrders RepairOrders, A" _
        , "YS_amdj.dbo.RODetails RODetails" & Chr(13) & "" & Chr(10) & "WHERE RepairOrders.RONo = RODetails.RONo AND ((RepairOrders.ROCustName Like '" & Name & "%') AND (RepairOrders.RODate>={ts '" & dt1 & "'} And RepairOrders.RODate<={ts _
        , '" & dt2 & "'} ) )" & Chr(13) & "" & Chr(10) & "ORDER BY RepairOrders.RODate")

Open in new window

amdjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

YiogiCommented:
Your problem is you split your string into two lines.
The code below should work.
.CommandText = Array( _
        "SELECT RepairOrders.ROustNo, RepairOrders.ROCustName, RepairOrders.RODate, RepairOrders.ROMake, RepairOrders.RONo, RODetails.ROItemDesc, RODetails.RONo" & Chr(13) & "" & Chr(10) & "FROM AYS_amdj.dbo.RepairOrders RepairOrders, A" _
        , "YS_amdj.dbo.RODetails RODetails" & Chr(13) & "" & Chr(10) & "WHERE RepairOrders.RONo = RODetails.RONo AND ((RepairOrders.ROCustName Like '" & Name & "%') AND (RepairOrders.RODate>={ts '" & dt1 & "'} And RepairOrders.RODate<={ts, '" _
        & dt2 & "'} ) )" & Chr(13) & "" & Chr(10) & "ORDER BY RepairOrders.RODate")
 

Open in new window

0
amdjAuthor Commented:
That's stupid me... isn't that the commas is requres on the second line when it split?

Thanks a bunch!
0
YiogiCommented:
No commas are not required. The problem is you actually split your string constant. You cannot have string constants across multiple lines although your code can take as many lines as you wish.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
YiogiCommented:
Well not as many as you wish I have had in the past VBA saying that I had exceeded that limit. I don't remember the exact limit though. I also had procedures too large for VBA lol. It does have limits yes but unless running something really complex you won't meet them.
0
amdjAuthor Commented:
Quick solution and very helpful, I have been pulling my hair all day long on this.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.