Hello, using some VBA I was able to find online, I created a form that displays an image who's file path is stored in a table. The form works great, but I have to manually type the file path into a text box on the form. Is it possible to create a button (and macro??) that opens the normal windows browse for file feature and forwards the file path of the file selected to my text box so that it will automate the process? This seems like something that a lot of folks would like to know how to do. Thanks in advance!
Browse for a file from a Form
Collapse
X
-
-
The following Code Segment will:- Display the Microsoft Office File Dialog Box
- Set Filters to allow only specific Graphic File Formats
- Allow only a single File to be Selected
- Set the Default File Type for display to Bitmap (*.bmp)
- Show the Files in Detail View
- Write the Absolute PATH of the File selected to a Text Box named txtImagePath
Code:'First, set a Reference to the Microsoft Office XX.X Object Library Dim strButtonCaption As String Dim strDialogTitle As String 'Define your own Captions if necessary strButtonCaption = "Copy Path" strDialogTitle = "Select Graphic File" With Application.FileDialog(msoFileDialogFilePicker) With .Filters .Clear .Add "Windows Meta Files", "*.wmf" .Add "Enhanced Meta Files", "*.emf" .Add "Device Independent Bitmaps", "*.dib" .Add "Bitmaps", "*.bmp" .Add "Icons", "*.ico" .Add "Tag Image File Format", "*.tif" .Add "PC Paintbrush", "*.pcx" End With 'The Show Method returns True if 1 or more files are selected .AllowMultiSelect = False 'Critical Line .FilterIndex = 4 'Bitmap files .ButtonName = strButtonCaption .InitialFileName = vbNullString .InitialView = msoFileDialogViewDetails 'Detailed View .Title = strDialogTitle .InitialFileName = CurrentProject.Path & "\" If .Show Then Me![txtImagePath] = .SelectedItems(1) End If End With
Comment
Comment