Results 1 to 6 of 6
  1. #1
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172

    Help with Code to set ChartTitle Property

    Hi,

    I have this code in my Report:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If IsNull(Me.MyGraph.ColumnCount) Then
    Me.MyGraph.ChartTitle.Text = "No Data to Display for Previous Month"
    Else


    Me.MyGraph.ChartTitle.Text = "MyReportName - " & Format(DateAdd("m", -1, Now()), "mmmm")
    End If
    End Sub

    It used to work, and no longer does. I have tried changing "IsNull" to "=0" or ">= 1" with no success. I can get the chart title to display both "No Data to Display for Previous Month", but then it displays that chart title whether or not there is data in the chart. Same goes for displaying "MyReportName".

    So, I am guessing that the ColumnCount property is not working for some reason. I am wondering if there is a way to count the rows in the query the report is based on instead?

    Any help gratefully received.

    Kirsti

  2. #2
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Ok, I now have the code below. But the query the report is based on is a Paramater Query, and when I open the Report I get the Error: Too few paramaters, expected 2. The parameters are: Forms!frmMyForm!myfield1 and Forms!frmMyForm!myfield2 - but I don't know how to add this into the code.


    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim db As Database, rs As Recordset, strSQL As String
    Set db = CurrentDb
    strSQL = "Select * From qryMyQuery"
    Set rs = db.OpenRecordset(strSQL)
    If RecordCout = 0 Then
    Me.MyGraph.ChartTitle.Text = "No Data to Display for Previous Month"
    Else
    Me.MyGraph.ChartTitle.Text = "MyReportName - " & Format(DateAdd("m", -1, Now()), "mmmm")
    End If
    End Sub

    Kirsti

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Maybe don't need to refer to the form parameters.

    Not sure about recordset syntax and the If line should be:
    If rs.RecordCount = 0


    Could try this instead.

    If DCount("*", "qryMyQuery") = 0 Then
    Me.MyGraph.ChartTitle.Text = "No Data to Display for Previous Month"
    Else
    Me.MyGraph.ChartTitle.Text = "MyReportName - " & Format(DateAdd("m", -1, Now()), "mmmm")
    End If
    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.

  4. #4
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Ok. Sorry June I have been wasting your time. Actually, the query will ALWAYS return rows because I have placeholders in the query to fill the legend. No wonder my code wasn't working.
    So, my table looks like this:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	8 
Size:	4.9 KB 
ID:	7527

    So if there is going to be data in the chart, the Days_VAC and Type fields will always have data, and the Units field will always be >0. Now I've tried this code:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If IsNull([Queries]![MyQuery]![MyField]) Then
    Me.MyGraph.ChartTitle.Text = "No Data to Display for Previous Month"
    Else
    Me.MyGraph.ChartTitle.Text = "MyReportName - " & Format(DateAdd("m", -1, Now()), "mmmm")
    End If
    End Sub


    But I'm getting an error. I imagine I need to somehow code it to say if that field is null for every row... But I don't know how to do that.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Try:

    If IsNull(DLookup("Units","qryMyQuery","Units<>0")) Then
    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 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Thank you June! I've tested both with data and without and FINALLY get the right result!

    Thank you thank you thank you thank you.

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

Similar Threads

  1. Global Property Changes
    By ajetrumpet in forum Code Repository
    Replies: 2
    Last Post: 08-07-2012, 10:31 PM
  2. Property value is too large.
    By foru in forum Access
    Replies: 9
    Last Post: 06-28-2011, 03:55 PM
  3. Can Grow Property
    By chum in forum Reports
    Replies: 3
    Last Post: 01-25-2010, 11:10 AM
  4. Can Grow Property
    By MFeightner in forum Reports
    Replies: 0
    Last Post: 06-24-2009, 11:50 AM
  5. Replies: 1
    Last Post: 08-10-2008, 01:09 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