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

    Run-time error 1004

    Hi, I have a Report with a Chart in it. The chart title is set via code.



    This works perfectly when there is data in the chart, but if the chart doesn't contain data, I can't open the report to view the empty graph. Instead I get: Run-time error'1004': Unable to set the Text property of the ChartTitle class.

    Is anyone familiar with this and/or know how to handle it?

    Thanks,
    Kirsti

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    In the code that sets the title need to verify there is data first. If not, skip the title edit.
    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 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Thanks June - could you please give me an example of what that code would look like?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Try something like:

    If Me.Graph74.ColumnCount > 0 Then
    'some code here
    End If

    What event is the code in to set the title?
    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.

  5. #5
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Thanks June, the code is set to the Detail_Format event.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Okay, try my suggestion in there. Do you know the Format event executes only when report in NormalView (to printer) or PrintPreview?
    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.

  7. #7
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Hi again, I didn't know that - thank you. That isn't a problem for this particular report but very helpful to know.

    I have tried your suggestion, and don't have it working as yet. My code is:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me.Graph10.ColumnCount < 0 Then
    MsgBox "No Data to Display"
    Else
    Me.Graph10.ChartTitle.Text = "MyReportTitle - " & Format(DateAdd("m", -1, Now()), "mmmm")
    End If
    End Sub

    I am getting the same Run Time error with this code.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Comment out the ChartTitle line and run. If don't get error then know something is wrong with that line. Do you want to provide project for analysis?
    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.

  9. #9
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    It is that line that is causing the Runtime error - however only when there is no data in the chart. I have that identical line in other reports where there is data, and it works perfectly.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Just noticed you use <0. I doubt ColumnCount could ever be less than zero. It will be zero or greater. Step debug. My guess is the ChartTitle line is executing because ColumnCount is not <0. Your code must use =0. My example used >0 meaning run ChartTitle code only if there are columns. I did not know you wanted a message box.
    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.

  11. #11
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    You're right. I played around a lot and didn't get it working - hence the < 0 that I forgot to change back. But yes - when I put = 0 it opens correctly. I didn't want a messagebox, just had that in there for testing - I didn't realise you could have an If Then Else without a Then argument. But have just taken the messagebox line out of my code, and it is now exactly the way I want it.

    Thanks once again, June!

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

Similar Threads

  1. Replies: 5
    Last Post: 03-27-2012, 01:40 PM
  2. Run Time Error '94'
    By dongodu in forum Programming
    Replies: 14
    Last Post: 10-23-2011, 08:08 AM
  3. Error in Run Time
    By dongodu in forum Queries
    Replies: 5
    Last Post: 07-24-2011, 06:54 PM
  4. Replies: 2
    Last Post: 12-23-2010, 09:11 AM
  5. Replies: 2
    Last Post: 12-02-2010, 02:35 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