Hey guys - Can anyone help me figure out whats wrong with the IF statement below? For some reason, the else statement is evaluating whether or not If ext1 = jpg Or png Or bmp Or jpeg Or tiff Then is true.
I get a Runtime Error 2220 at line Me.cmdAttach1.Picture = fileType1
I get a Runtime Error 2220 at line Me.cmdAttach1.Picture = fileType1
Code:
Dim fdialog1 As Object
Dim strfile1 As String
Dim sourceDir1 As String
Dim varItem1 As Variant
Dim fileType1 As String
Dim ext1 As String
' Open File Picker
Set fdialog1 = Application.FileDialog(3)
fdialog1.allowMultiSelect = False
If fdialog1.show Then
For Each varItem1 In fdialog1.selectedItems
strfile1 = Dir(varItem1)
' Get source directory from selected file and set to sourceDir1
sourceDir1 = Left(varItem1, Len(varItem1) - Len(strfile1))
' Assign txtAttachment1 object to source folder & file name
Me.txtAttachment1 = sourceDir1 + strfile1
' Get extension from selected item
ext1 = Right(varItem1, Len(varItem1) - InStrRev(varItem1, "."))
MsgBox "The ext1 value is " + ext1
' Check for compatible image for thumbnail
If ext1 = jpg Or png Or bmp Or jpeg Or tiff Then
' Display image thumbnail
Me.cmdAttach1.Picture = Me.txtAttachment1.Value
Else
' Set thumbnail icon for non-image files
fileType1 = "B:\icons\" & Mid(varItem1, InStrRev(varItem1, ".") + 1) & ".png"
' Display icon for non-image files
Me.cmdAttach1.Picture = fileType1
End If