Results 1 to 11 of 11
  1. #1
    Kirsti is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172

    Dynamic Chart Title in Report

    Hi,



    I have a chart in a report based on data for the previous month - Month(Now())-1 in the query.

    The chart title doesn't seem to allow for any code. At the moment I have named it: 'Number of Applications - Previous Month', but I would like some help with some VBA to code the title, so that the month actually shows in the report title. i.e. If I run the report today, I would like it to say: 'Number of Applications - February', and then when I run it in April I'd like it to say: 'Number of Applications - March'.

    Is this possible, and is anyone able to help me with this?

    Thanks,
    Kirsti

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Need VBA. Use the Format event of whatever section of report the graph is in, I am guessing the Detail section.

    Review this http://social.msdn.microsoft.com/For...-a91c7cd0b5fc/

    Try:
    Me.yourgraphname.ChartTitle = "Number of Applications - " & Month(Now())-1
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Kirsti is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Ok, I'm having trouble.

    You are right, my graph is in the Detail section. I have:

    Private Sub Detail_Format()
    Me.Graph4.ChartTitle = "Test"
    End Sub

    But I am getting an error:
    "The expression On Format you entered as the event property setting produced the following error:Procedure declaration does not match description of event or procedure having the same name."

  4. #4
    Kirsti is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Got it working with:

    Private Sub Detail_Format (Cancel As Integer, FormatCount As Integer)
    Me.Graph4.ChartTitle.Text = "Test"
    End sub

    Now just have to have a play and test the Month(Now()-1) part!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If you want month name instead of number:

    Format(DateAdd("m",-1,Now()),"mmmm")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Kirsti is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Ok,

    Now working perfectly!!


    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Me.Graph4.ChartTitle.Text = "Number of Applications - " & Choose(Month(Now()) - 1, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
    End Sub

    Thanks for getting me started June.

  7. #7
    Kirsti is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Oooh, perfect.

    I posted my reply before seeing yours, but that's much better without the hard coding, and also works perfectly.

    Thanks again.

  8. #8
    Kirsti is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    One more question - If there is no data for the previous month, the report is throwing an error, which makes sense, but would you be able to suggest some kind of error handling code?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Throwing what kind of error? If there is no data is there reason to run report?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    I put dummy data in the table yesterday to fix, and now I can't seem to replicate the error, I think I'll just worry about it later if I see the error again. And you're right, in theory there is no reason to run the report if there's no data, but I have set up a button on a form to e-mail all reports to management, and they can hit that button whenever they like, so it is possible there will sometimes be reports with no data created.

    Thanks again for all of your help with this June.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Can use OnNoData event of form to handle when no data.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 01-22-2012, 02:41 PM
  2. Replies: 1
    Last Post: 11-21-2011, 03:22 PM
  3. Variable Report Title in Access 2010
    By Titan078 in forum Reports
    Replies: 4
    Last Post: 11-17-2010, 11:22 AM
  4. Chart Workspace Title
    By thestappa in forum Queries
    Replies: 0
    Last Post: 07-07-2010, 10:23 AM
  5. Replies: 20
    Last Post: 05-24-2010, 06:31 AM

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