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