Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2005, 09:37 AM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question why saving failed with following code

Hi, I wrote following code to query some tables (sybase)

sqlStr = "SELECT r.Desk, r.LimitSubGroup, l.LimitName, r.RealDataColumnShift," & _
            " l.ReportType, r.Column, r.RowNum, s.Value" & _
            " FROM ReportTemplate r, LimitDefinition l, RiskRptDetails s" & _
            " WHERE r.SheetName = 'CreditDeltaDetail' " & _
            " AND r.TemplateName='GFM.xlt' " & _
            " AND s.PositionDate='" & Format(positionDate, "mm/dd/yyyy") & "'" & _
            " AND r.LimitId = l.LimitId" & _
            " AND l.ReportType not in('DeskID')" & _
            " AND r.Desk = s.Grouping" & _
            " AND r.LimitSubGroup = s.SubGroup" & _
            " AND r.LimitId = s.LimitId"

    rstData.Open sqlStr, dbconn, adOpenKeyset, adLockReadOnly
    ....
Then I clicked save button for this VBAproject, I got error message saying "Excel cannot save this file" and excel renamed my worksheet to temporay name such as E03F0190.

Finally I changed above code to

sqlStr = "SELECT r.Desk, r.LimitSubGroup, l.LimitName, r.RealDataColumnShift," & _
            " l.ReportType, r.Column, r.RowNum, s.Value" & _
            " FROM ReportTemplate r, LimitDefinition l, RiskRptDetails s" & _
            " WHERE r.SheetName = 'CreditDeltaDetail' AND r.TemplateName='GFM.xlt'" & _
            " AND s.PositionDate='" + positionDateStr + "'" & _
            " AND r.LimitId = l.LimitId" & _
            " AND r.Desk = s.Grouping" & _
            " AND r.LimitSubGroup = s.SubGroup" & _
            " AND r.LimitId = s.LimitId"

    rstData.Open sqlStr, dbconn, adOpenKeyset, adLockReadOnly
......

And excel allowed saving this time.

Is this because sqlStr is too large? I checked String limit(2^16). sqlStr is definitely within that limit. So what's wrong with the first sqlStr?

Thanks a lot
Wendy
 
Old April 6th, 2005, 01:37 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You might have hit a line-continuation-character (“_”) count limit.
The limit is 25 (I think) in VB. Might be different in Excel VBA.
 
Old April 7th, 2005, 08:45 AM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot. I tried a dummy string and it seems that for Excel VBA the line-continuation-character (“_”) limit is also 25. Does the module size have limit? Or the query for database has limit?

 
Old April 7th, 2005, 10:15 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

does it work if you place your string in an array?

rstData.Open Array("SELECT r.Desk, r.LimitSubGroup, l.LimitName, r.RealDataColumnShift,", " l.ReportType, r.Column, r.RowNum, s.Value", " FROM ReportTemplate r, LimitDefinition l, RiskRptDetails s", " WHERE r.SheetName = 'CreditDeltaDetail' ", " AND r.TemplateName='GFM.xlt' ", " AND s.PositionDate='" & Format(positionDate, "mm/dd/yyyy") & "'", " AND r.LimitId = l.LimitId", " AND l.ReportType not in('DeskID')", " AND r.Desk = s.Grouping", " AND r.LimitSubGroup = s.SubGroup", " AND r.LimitId = s.LimitId"), dbconn, adOpenKeyset, adLockReadOnly

Mat


 
Old April 7th, 2005, 11:57 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

One of the things I have resorted to from time to time is to take a long, line-continuationed string that’s giving me trouble, and insert a “'” just before one of the “&”s to turn the rest of the string into comment (comments support line-continuation), then see if the string will fly.

You can highlight and drag/drop the “'” to a location farther down the string, a little bit at a time, to try to see just exactly where the problem arrises.

I would really like to know exactly what part of the statement is generating the problem...
 
Old April 8th, 2005, 03:38 PM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I used ' to comment the string little by little. Then it turns out

            " WHERE r.SheetName = 'CreditDeltaDetail' " & _
            " AND r.TemplateName='GFM.xlt' " & _

failed. It works if I combined them into one line
 " WHERE r.SheetName = 'CreditDeltaDetail' AND TemplateName='GFM.xlt' " & _

The wired thing is if I copy that failed code to a brand new worksheet, everything works fine.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help please!The compiler failed with error code 1. nichola_x_rose BOOK: ASP.NET Website Programming Problem-Design-Solution 0 July 1st, 2008 02:34 AM
Question on saving changes to databases PatCiferri SQL Server 2005 1 December 4th, 2007 04:56 PM
Proc execution failed from CS code nkrust ASP.NET 2.0 Professional 0 August 30th, 2007 01:28 AM
EXCEL question saving a file saving the the first macupryk VS.NET 2002/2003 0 January 6th, 2005 05:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.