+ Reply to Thread
Results 1 to 19 of 19

Ms Access and Ms Excel VBA - Dynamic Charts

  1. #1
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Thumbs up Ms Access and Ms Excel VBA - Dynamic Charts

    Hello everybody,

    I have a strange problem. I must generate mutliple charts dynamically from a Ms Access database. The solution we wanted to implement is that we export all the Data in Excel, and from then we generate the charts. It's working fine when the charts are define statically. But when it's time to do it dynamically, it doesn't work.

    I'll give you an example :

    Please Login or Register  to view this content.
    That code is working well. But, when I'm adapting my solution in a function like :

    Please Login or Register  to view this content.

    and the following code who calls the Procedure

    Please Login or Register  to view this content.
    The problems is that I don't see the series at all in the chart and there is no error message. It's like it sees nothing. Do you have any idea, because it's working well with the static code ?

    Thank you for your help !

    Daniel
    Last edited by dagagnon; 12-05-2012 at 04:00 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Daniel

    Where do you have the second code?

    If it's in Access then Excel constants like xlLine won't be recognised unless you have a reference to the appropriate Excel library.

    PS Where's the rest of the code? For example the part that opens Excel.
    Last edited by Norie; 12-04-2012 at 01:51 PM.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Hi Norie,

    my code is respecting the following order, so it's called directly before ChartGenerator procedure, but in an other Sub.

    1) The user select the parameters 2) The data is imported in Excel Sheets 3) The data is process for some chart 4) We generate the Charts.

    I use the ByRef as much as I can. But it doesn't work with collections.

    All the code is run form Ms Access.

    What I don't understand is why : .SeriesCollection(1).Values = "='Sheet1'!$H$4:$J$4" but not when it's comming from a variable. Or maybe I should type it String

    My goal is to have the ranges for each charts in the database and feed them to my procedure.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Have you stepped through the code to see what's happening?

    Also, do you have a reference to the Excel object library?

  5. #5
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Yes, I have a reference to Application.Excel, that is not the problem since I generate the charts statically. I'm generating 6 charts and they are all working well. But my goal is to do the same dynamically. I didn't try to step inside the code. Maybe I should.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Dagagnon,

    Welcome to the forum.

    I have added code tags to your 1st post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  7. #7
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Thank you for reminding me that rule Arlette !

    I wonder if there is a different way to assign the series dynamically to my dynamic charts...

  8. #8
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Hi Norie,

    I'm working with confidential data, so I can't send you the whole project, but I'll give you the most information possible.

    Please Login or Register  to view this content.
    Edited the code for all the 5 other static charts but they are all working well.

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 12-05-2012 at 10:06 AM.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Does the code work if you don't use a separate sub?

  10. #10
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Quote Originally Posted by Norie View Post
    Does the code work if you don't use a separate sub?
    I haven't try that, it's true, but I do a lot of stuff in other subs. Thought using it in the same sub would make me loose the advantage of generic code. Other then that, it's easier to use static charts.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    I've just noticed something - you are adding the new series after everything else here.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Yeah, I know, but the Charts.Add method create a new Collection by default. But the code fails even before that. It gives me a 1004 - Invalid paramter S
    Last edited by jeffreybrown; 12-05-2012 at 10:05 AM. Reason: No need to reference entire quotes.

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    which line gives the error?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  14. #14
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Hi JosephP

    Quote Originally Posted by JosephP View Post
    which line gives the error?

    Please Login or Register  to view this content.
    That line produce the error.

  15. #15
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    what is the actual (not assumed!) value of parametre at that point and what is in the cell to which it refers?

  16. #16
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Quote Originally Posted by JosephP View Post
    what is the actual (not assumed!) value of parametre at that point and what is in the cell to which it refers?
    I know the exact value

    $B$3

  17. #17
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    and what is in the cell?

    in your earlier code you had
    Please Login or Register  to view this content.
    which should be Excel.Application

  18. #18
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Re: Ms Access and Ms Excel VBA - Dynamic Charts

    Quote Originally Posted by JosephP View Post
    and what is in the cell?

    in your earlier code you had
    Please Login or Register  to view this content.
    which should be Excel.Application

    The value in the cell is a text, because it's the name of the series.

  19. #19
    Registered User
    Join Date
    12-03-2012
    Location
    Canada
    MS-Off Ver
    Access 2007 Excel 2007
    Posts
    48

    Thumbs up Re: Ms Access and Ms Excel VBA - Dynamic Charts

    I found the solution to my problem, it's the SeriesCollection index that was the problem, it can't be zero.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1