Browse for filename without Common Dialog Control

fredalina

Registered User.
Local time
Today, 15:17
Joined
Jan 23, 2007
Messages
163
I do not have the Common Dialog Control installed on my computer (and apparently getting it installed requires more from my company than I have time to invest).

I have a form where a user inputs data that is used for a report. A command button will create a report from the data, save it as a .SNP document based on the ID field into a server folder, and e-mail the .SNP as an attachment. All of this works fine.

I also want the ability to include other attachments in the e-mail as well (i.e. picture files that depict the damages the report describes). There are 8 text fields for the user to input the path to as many as 8 attachments (AttPath1, AttPath2, ... , AttPath8), and the file that the path leads to will be attached through .Addattachment. This works fine as well.

i would like for the user to be able to browse for the filename to eliminate typo or other errors. This is where the trouble is.

The first text box is AttPath1, and the command button for the first path is cmdBrowse1.

Can you help me? i've found examples online but they are way over my programming capabilities as far as converting to my particular application.

Thanks!
 
If anyone searches this in the future, i found this code which is much closer to my VBA skill level, and in basically just C/Ping, it worked fine:

Private Sub cmdBrowse1_Click()
'Creates the code to Browse through files to select attachments.
On Error GoTo Err_cmdBrowse1_Click
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)

'Reference the FileDialog object.
With fd
'Allow the user to select only one file.
.AllowMultiSelect = False
' Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
Me.AttPath1.Value = vrtSelectedItem
Next vrtSelectedItem
'The user pressed Cancel.
Else
Set fd = Nothing
Exit Sub
End If
End With
' Set form controls
Me.AttPath1.Enabled = True
Me.AttPath1.SetFocus
Me.cmdBrowse1.Enabled = True
'Set the object variable to Nothing.
Set fd = Nothing
Exit_cmdBrowse1_Click:
Exit Sub
Err_cmdBrowse1_Click:
MsgBox Err.Description
Resume

End Sub
 

Users who are viewing this thread

Back
Top Bottom