Hello -
I have a form which has a field - Me.txt_Email_Attachment_1 and a button btn_attachment_add_1
I want to open the file picker, browse to a file and insert the file name and path into the textbox.
The code I have is basically working, but I would like to improve this with error checking etc. I am trying to learn code and so am hoping that someone could help me improve the sub.
For instance if I select a file then code runs fine, but if I cancel the file picker dialog box, the code errors.
I would greatly appreciate any help
Thank you Mark
CODE:
Private Sub btn_attachment_add_1_DblClick(Cancel As Integer)
Dim dialog As FileDialog
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
With dialog
.AllowMultiSelect = False
.Show
Me.txt_Email_Attachment_1 = .SelectedItems.Item(1)
End With
End Sub
I have a form which has a field - Me.txt_Email_Attachment_1 and a button btn_attachment_add_1
I want to open the file picker, browse to a file and insert the file name and path into the textbox.
The code I have is basically working, but I would like to improve this with error checking etc. I am trying to learn code and so am hoping that someone could help me improve the sub.
For instance if I select a file then code runs fine, but if I cancel the file picker dialog box, the code errors.
I would greatly appreciate any help
Thank you Mark
CODE:
Private Sub btn_attachment_add_1_DblClick(Cancel As Integer)
Dim dialog As FileDialog
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
With dialog
.AllowMultiSelect = False
.Show
Me.txt_Email_Attachment_1 = .SelectedItems.Item(1)
End With
End Sub