This one has me stumped. I am using Access 2016 in Office 365. I have a database where a user has an input form to collect data and, if they wish, add a picture to the record. This works just fine.
The user can then send an HTML email of the record out with the picture embedded. This I got working as well. However, there is a disconnect. I am still testing everything and ran into a bug that I can't figure out out to clear. If I manually type in the the file location for the picture, i.e. Z:\EMailNotes\EMailPictures\MyPicture.jpg into the source table, the picture sends no problem. However, if I add the picture to the table using the input form and the following code and then send the email, I get an "Error! Filename not specified" message in the email where the image should be embedded.
I checked and it's adding an extra space at the end of the file name... I would have thought that this statement:
would have cleared any extra spaces.
The user can then send an HTML email of the record out with the picture embedded. This I got working as well. However, there is a disconnect. I am still testing everything and ran into a bug that I can't figure out out to clear. If I manually type in the the file location for the picture, i.e. Z:\EMailNotes\EMailPictures\MyPicture.jpg into the source table, the picture sends no problem. However, if I add the picture to the table using the input form and the following code and then send the email, I get an "Error! Filename not specified" message in the email where the image should be embedded.
Code:
Private Sub Image46_DblClick(Cancel As Integer)
On Error GoTo Err_Image46_DblClick
Dim ofn As OPENFILENAME
Dim PictureFile As String
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Me.Hwnd
ofn.lpstrFilter = "Jpeg Files (*.jpg)" + Chr$(0) + "*.jpg" + Chr$(0) + _
"Graphic Files (*.gif)" + Chr$(0) + "*.gif" + _
Chr$(0) + "Bitmaps (*.bmp)" + Chr$(0) + "(*.bmp)" + Chr$(0)
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = "Z:\EMailNotes\EMailPictures" 'CurDir
ofn.lpstrTitle = "Find Graphic files"
ofn.flags = 0
Dim A
A = GetOpenFileName(ofn)
HoldPicturePath = Trim$(ofn.lpstrFile)
If HoldPicturePath <> "" Then
Me.PictureFile = HoldPicturePath
Image46.Picture = Me.PictureFile
Else
Image46.Picture = "Z:\EMailNotes\EMailPictures\NoPicture.jpg"
Me.PictureFile.Value = "Z:\EMailNotes\EMailPictures\NoPicture.jpg"
End If
Exit_Image46_DblClick:
Exit Sub
Err_Image46_DblClick:
Select Case Err.Number
Case 2220
MsgBox "You have cancelled your image search.", vbInformation
Case Else
MsgBox Err.Description
End Select
Resume Exit_Image46_DblClick
End Sub
I checked and it's adding an extra space at the end of the file name... I would have thought that this statement:
Code:
HoldPicturePath = Trim$(ofn.lpstrFile)
would have cleared any extra spaces.
Last edited: