I am using a bit of code that allows user to browse for an address of a file to attach to an email. It works beautifully unless the user cancels the browse operation, after which an error message pops up: "The expression you entered has an invalid reference to the parent property." How to avoid the runtime error message?
Code:
Private Sub Command40_Click()
On Error GoTo Err_Command40_Click
Dim Myfile As Office.FileDialog
Set Myfile = Application.FileDialog(msoFileDialogFilePicker)
Dim FileAddress As String
With Myfile
.Filters.Clear
.AllowMultiSelect = False
.Show
FileAddress = .SelectedItems(1)
End With
If Len(AttachmentLocation) <> 0 Then
AttachmentLocation = AttachmentLocation & "; " & FileAddress
Else
AttachmentLocation = FileAddress
End If
If Me.Dirty Then Me.Dirty = False
Me.Refresh
Exit_Command40_Click:
Exit Sub
Err_Command40_Click:
MsgBox err.Description
Resume Exit_Command40_Click
End Sub