Error! Filename not specified (1 Viewer)

Indigo

Registered User.
Local time
Today, 05:23
Joined
Nov 12, 2008
Messages
241
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.

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:

theDBguy

I’m here to help
Staff member
Local time
Today, 00:53
Joined
Oct 29, 2018
Messages
21,477
Hi. Have you tried commenting out the error handler and then stepping through the code?
 

Indigo

Registered User.
Local time
Today, 05:23
Joined
Nov 12, 2008
Messages
241
DBGuy - I was revising my post when you posted your reply... could you look it again? Thank you.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:53
Joined
Oct 29, 2018
Messages
21,477
DBGuy - I was revising my post when you posted your reply... could you look it again? Thank you.
Hi. The first thing I would recommend is add Option Explicit to the top of your code module, if you don't have it already. Then, explicitly declare all your variable data types.



Should HoldPicturePath be a Text variable? If so, declare it as such and then try the code again. See if it still holds an extra space afterwards. If so, try Trim(HoldPicturePath) instead. If it still holds a space, then it's not a space.
 

Indigo

Registered User.
Local time
Today, 05:23
Joined
Nov 12, 2008
Messages
241
This at the top of my form:

Code:
Option Compare Database
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public HoldPicturePath As String
Option Explicit

I went in and did an update query to the table to: SET PictureFile = Trim([PictureFile]) to remove any spaces and tried to run the email function and am still getting the same Error! Filename not specified
 

Indigo

Registered User.
Local time
Today, 05:23
Joined
Nov 12, 2008
Messages
241
I tried your suggestion as well - Trim(HoldPicturePath) and also have

Code:
DeBug.Print HoldPicturePath [\CODE]

in my code and there is still a space at the end despite the Trim... so, I guess it's not a space....  :-(   

I don't know what do do from here.....
 

Users who are viewing this thread

Top Bottom