Add attachment with VBA code, getting bug (1 Viewer)

SachAccess

Active member
Local time
Today, 12:47
Joined
Nov 22, 2021
Messages
389
Hi,
I am trying to add attachment through a button on a Form. I have copied below code (forgot to copy the URL) for my use.
Am getting bug at below line.
'With Application.FileDialog(msoFileDialogFilePicker)'

I am getting bug as Method 'FileDialog' of object '_Application failed.
Can anyone please help me with this. Thanks.

Code:
Private Sub Btn_AttachFile_Click()
  Dim varFile As Variant
 
    With Application.FileDialog(msoFileDialogFilePicker)
        With .Filters
            .Clear
        End With
        
        .AllowMultiSelect = False
        .InitialFileName = vbNullString
        .InitialView = msoFileDialogViewDetails
        
        If .Show = True Then
                For Each varFile In .SelectedItems
                Me![File] = varFile
                Next
            Else
                MsgBox "No file attached ! "
        End If
    End With
End Sub
 

Kayleigh

Member
Local time
Today, 08:17
Joined
Sep 24, 2020
Messages
706
I don't think you should have a space before the .FileDialog
 

Users who are viewing this thread

Top Bottom