Results 1 to 10 of 10
  1. #1
    BrettAltea is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    2

    Error closing form after exporting graph to gif

    Hi everyone



    I have some code to export a graph on a form as a gif. I am unsure where I got the code from as it was uncommented but it looks like it was code by Graeme Wilson.
    Anyway the code works well and exports the graph as a gif with no errors however after exporting when I close the form I get the following msgbox, "Sorry, an unexpected error occurred. Please exit and restart (the database). If you've made recent design changes, please save your work before you exit." And then I have to click the OK button three times and the form then closes with no other issues. The following code is the only code on the form:
    Code:
    Option Compare Database
    
    Private Sub btnExportGraph_Click()
    On Error GoTo Err_btnExportGraph_Click
    Dim strExportGraph
    Dim oleGrf As Object
    Dim strFileName As String
    Dim FileSave As String
    Dim i As Integer
    Dim blnGraph As Boolean
    Dim strErrMsg As String
    
    
    strExportGraph = DLookup("GraphPath", "Paths")
    Set oleGrf = Me.graphUlcer.Object
    
    
    strFileName = Nz(DLookup("[First Name]", "tblclientassessmentdetails", "[UniqueAutonumber] = " & Me.ClientID))
    strFileName = strFileName & " " & Nz(DLookup("[Last Name]", "tblclientassessmentdetails", "[UniqueAutonumber] = " & Me.ClientID))
    strFileName = strFileName & " " & DLookup("[Location]", "tblUlcer", "[UlcerID] = " & Me![UlcerID])
    strFileName = ReplaceQuotes(strFileName)
    strFileName = Replace(strFileName, "/", "")
    strFileName = Replace(strFileName, "\", "")
    strFileName = Replace(strFileName, "*", "")
    
    
                If IsFileDIR(strExportGraph & strFileName & " graph.gif") = 0 Then
                    strFileName = strExportGraph & strFileName & " graph.gif"
                    oleGrf.Export FileName:=strFileName, FilterName:="gif"
                Else
                    blnGraph = False
                    i = 1
                    Do Until blnGraph = True
                        FileSave = strExportGraph & strFileName & "graph" & "+" & i & ".gif"
                        If IsFileDIR(FileSave) = 0 Then
                            oleGrf.Export FileName:=FileSave, FilterName:="gif"
                            blnGraph = True
                            strFileName = FileSave
                        Else
                            i = i + 1
                        End If
                    Loop
                End If
    
    
    'strFileName = strFileName & " graph.gif"
    
    
    MsgBox "The graph has been exported as a gif to " & strFileName, vbOKOnly, "Graph exported as gif file ..."
    
    
    Set oleGrf = Nothing
    Exit_btnExportGraph_Click:
    Set oleGrf = Nothing
        Exit Sub
    
    
    Err_btnExportGraph_Click:
        Select Case Err
            Case Else
                strErrMsg = strErrMsg & "Error #: " & Format$(Err.Number) & vbCrLf & vbCrLf
                strErrMsg = strErrMsg & "Error Description: " & Err.Description & vbCrLf
                MsgBox strErrMsg, vbInformation, "cmdEmailGraph_Click"
                Resume Exit_btnExportGraph_Click
        End Select
    
    
    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Foremost, I'd try compacting/repairing the db after backing it up. The message is not helpful at all. Here are some things that may or may not be relevant to the problem.

    Option Explicit should be at the top of every module. Some would say if not, you deserve all the misery you get!
    strExportGraph = DLookup("GraphPath", "Paths") - the variable predicate str indicates you're expecting a string, but you've not declared it, so it is a variant.
    strFileName is a string, but you don't declare a default for Nz. If it returns a Null you'll get a zero or zero length string.
    If the problem persists after compacting (but the code runs without error) try clicking Save after the code runs

    Special characters in directory or file names: while + seems to be allowed, it is a bad idea IMHO
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    BrettAltea is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    2
    Thanks Micron. I made all suggested changes - added Option Explicit, set strExportGraph as string, added Nz to strFileName, compact/repaired, saved, removed "+". Still the same issue. No errors while running code. Only after all code has finished when I manually close the form I get the error. This happens on three different forms that I export graphs on. Code is not running at the time of closing the forms.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    added Nz to strFileName
    Not sure what you mean by that because you were already using the function on the variable, you just weren't specifiying a default.
    The only other thing I can think of is that the problem is in the function being called:
    IsFileDIR(strExportGraph & strFileName & " graph.gif")
    Perhaps an application level error has been caused but not revealed, but raises its ugly head when you try to terminate the "bond" by closing the form. Maybe apply the same thinking to the module that contains the function. About all else I can say is to recreate the form, but I'd look into the other parts of the db that are related.

  5. #5
    hotdog0627 is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2021
    Posts
    3
    Quote Originally Posted by Micron View Post
    added Nz to strFileName
    Not sure what you mean by that because you were already using the function on the variable, you just weren't specifiying a default.
    The only other thing I can think of is that the problem is in the function being called:
    IsFileDIR(strExportGraph & strFileName & " graph.gif")
    Perhaps an application level error has been caused but not revealed, but raises its ugly head when you try to terminate the "bond" by closing the form. Maybe apply the same thinking to the module that contains the function. About all else I can say is to recreate the form, but I'd look into the other parts of the db that are related.
    Hi, were you able to figure out why? I am experiencing the exact same issue. I have Office365 and my code is very simple:

    fname = "C:\DChart.png"
    Me.Graph9.Export fname
    CreateObject("Shell.Application").Open (fname)

    If I dont export, there is no error when you close the form. Very strange...

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I never noticed until now that the format being used is .gif AFAIK, Access doesn't support .gif type although the OLE object being worked with might. I'd try other formats that Access works nicely with. Perhaps jpg will be OK. .bmp is an Access 'favourite' but it's a much larger file size.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    hotdog0627 is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2021
    Posts
    3
    Quote Originally Posted by Micron View Post
    I never noticed until now that the format being used is .gif AFAIK, Access doesn't support .gif type although the OLE object being worked with might. I'd try other formats that Access works nicely with. Perhaps jpg will be OK. .bmp is an Access 'favourite' but it's a much larger file size.
    Same issue with JPG, And BMP format wont even export.

    To replicate, create a form then add Chart. If you dont Export the chart the Form closes without issues.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    perhaps Google it for more references, or see https://www.access-programmers.co.uk...eg-gif.305265/
    To replicate, create a form then add Chart.
    I developed a hate/hate relationship with Access charts long ago so no thanks.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    hotdog0627 is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2021
    Posts
    3

    Thumbs up

    Quote Originally Posted by Micron View Post
    perhaps Google it for more references, or see https://www.access-programmers.co.uk...eg-gif.305265/

    I developed a hate/hate relationship with Access charts long ago so no thanks.
    Thank you very much for the link above. The code snippets there solved my issue. This sample code to be exact....

    Set grpApp = Nothing Set grpApp = Me.AdvancedGraph.Object
    grpApp.export "C:\Access programmer\TestJHB.jpg"
    Me.AdvancedGraph.Locked = False
    Me.AdvancedGraph.Enabled = True

    Set grpApp = Nothing
    Me.AdvancedGraph.Action = acOLEClose
    Me.AdvancedGraph.Locked = True
    Me.AdvancedGraph.Enabled = False

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    We didn't see your code so is the take away here that you have to close the ole object before closing the form?
    I wonder what you'd get if you changed jpg back to .gif.
    Glad those links were of some help & thanks for posting your solution.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 24
    Last Post: 07-28-2015, 10:50 AM
  2. Error Message When Closing a Form w/ Macro
    By KCC47 in forum Programming
    Replies: 8
    Last Post: 11-14-2014, 03:35 PM
  3. Automatically exporting a report on closing access
    By Alvin Schultz in forum Import/Export Data
    Replies: 8
    Last Post: 01-13-2014, 09:08 PM
  4. Replies: 5
    Last Post: 12-22-2011, 01:12 PM
  5. Replies: 3
    Last Post: 01-10-2011, 10: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