Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    you're right, fixed it and Sql string works fine as recordsource

    but if i use sql as subquery like that

    Code:
       Me.AnalisiOperazioneGrafico.RowSource = "SELECT IDtrattativa, NomeCognome, [Ricavi] AS Valore, 'Redditivitą' AS CostiRicavi FROM (" & Sql & ") " & _                                           "UNION SELECT IDtrattativa, NomeCognome, [costi], 'Costi' FROM  (" & Sql & ");"
    i get the same error.

  2. #17
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    i tried this one
    Code:
       Me.AnalisiOperazioneGrafico.RowSource = "SELECT IDtrattativa, NomeCognome, [Ricavi] AS Valore, ""Redditivitą"" AS CostiRicavi FROM (" & Sql & "); "
    and it worked! maybe the problem is the union query?

  3. #18
    hci_jon is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2019
    Location
    Montgomery, IL
    Posts
    9
    Your subquery you are trying to build is too long.
    A recordsource of a control can only contain 2048 characters, so when you are trying to insert the subquery twice this is causing your string to go beyond the 2048 character limit, so that is what the error is saying.
    As you found, putting the sql in a saved query object fixes this, since you only have to reference the name of the saved query object rather than have all the sql in there.

    If you want to use your SQL instead, you will have to modify it to be shorter. You can do this by aliasing tables. Consider this query:

    SELECT Myreallylongtablename.MyReallyLongFieldName FROM Myreallylongtablename

    And notice how it is shortened:

    SELECT m.MyReallyLongFieldName FROM Myreallylongtablename m

    In your query this should shorten it quite a bit.

    If that doesn't make it short enough, you could make a query based on your original table object and also alias the field names to make them shorter, however you are back to needing another saved query.

  4. #19
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    thanks very much, very useful suggestion

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Subquery
    By Alex Motilal in forum Queries
    Replies: 3
    Last Post: 12-03-2020, 07:27 AM
  2. A subquery inside a subquery
    By tbjmobile@gmail.com in forum Queries
    Replies: 15
    Last Post: 04-22-2018, 11:48 AM
  3. TOP subquery
    By helpaccess in forum Queries
    Replies: 5
    Last Post: 08-30-2011, 10:28 AM
  4. Subquery sum?
    By anemoskkk in forum Access
    Replies: 0
    Last Post: 04-29-2011, 12:36 PM
  5. Subquery
    By combine21 in forum Queries
    Replies: 2
    Last Post: 09-17-2010, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums