473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

browse for file and then copy file path into text box

n8kindt
221 100+
i have an email program set up that is discussed in Bytes:array for email recipients thread. here's a picture to get the visual of what i'm trying to do



currently, the button at the bottom "Browse..." is an empty button. i want it to open an action that allows the user to select a file and then copy the file path to the attachment text box. just like you would in any email program. anybody know how i could go about doing this?
Jun 20 '08 #1
6 13228
ADezii
8,834 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. 'CRITICAL STEP!
  2. 'First, set a Reference to the Microsoft Office XX.X Object Library
  3.  
  4. Dim strButtonCaption As String
  5. Dim strDialogTitle As String
  6. Dim strAttachment As String
  7. Dim varItem As Variant
  8.  
  9. strButtonCaption = "<Your Button Name Here>"
  10. strDialogTitle = "<Your File Dialog Title Here>"
  11.  
  12. With Application.FileDialog(msoFileDialogFilePicker)
  13.   With .Filters
  14.     .Clear
  15.     .Add "All Files", "*.*"     'Allow ALL File types
  16.   End With
  17.  
  18.   'The Show Method returns True if 1 or more files are selected
  19.     .AllowMultiSelect = False       'Critical Line/Single File selection
  20.     '.FilterIndex = 1               'not really relevant
  21.     .ButtonName = strButtonCaption
  22.     .InitialFileName = vbNullString
  23.     .InitialView = msoFileDialogViewDetails     'Detailed View
  24.     .Title = strDialogTitle
  25.  
  26.   If .Show Then
  27.     For Each varItem In .SelectedItems      'There will only be 1 since
  28.                                             'AllowMultiSelect = False
  29.       'Assuming your Text Box Name is txtAttachment
  30.       strAttachment = varItem
  31.         Me![txtAttachment] = strAttachment
  32.     Next varItem
  33.   End If
  34. End With
Jun 20 '08 #2
n8kindt
221 100+
Expand|Select|Wrap|Line Numbers
  1. 'CRITICAL STEP!
  2. 'First, set a Reference to the Microsoft Office XX.X Object Library
  3.  
  4. Dim strButtonCaption As String
  5. Dim strDialogTitle As String
  6. Dim strAttachment As String
  7. Dim varItem As Variant
  8.  
  9. strButtonCaption = "<Your Button Name Here>"
  10. strDialogTitle = "<Your File Dialog Title Here>"
  11.  
  12. With Application.FileDialog(msoFileDialogFilePicker)
  13.   With .Filters
  14.     .Clear
  15.     .Add "All Files", "*.*"     'Allow ALL File types
  16.   End With
  17.  
  18.   'The Show Method returns True if 1 or more files are selected
  19.     .AllowMultiSelect = False       'Critical Line/Single File selection
  20.     '.FilterIndex = 1               'not really relevant
  21.     .ButtonName = strButtonCaption
  22.     .InitialFileName = vbNullString
  23.     .InitialView = msoFileDialogViewDetails     'Detailed View
  24.     .Title = strDialogTitle
  25.  
  26.   If .Show Then
  27.     For Each varItem In .SelectedItems      'There will only be 1 since
  28.                                             'AllowMultiSelect = False
  29.       'Assuming your Text Box Name is txtAttachment
  30.       strAttachment = varItem
  31.         Me![txtAttachment] = strAttachment
  32.     Next varItem
  33.   End If
  34. End With
WOW, unbelievable! that worked perfectly! where did u get that code? i googled all over the place and was unable to find ANYTHING. thanks a lot!

cheers,
nate
Jun 20 '08 #3
ADezii
8,834 Expert 8TB
WOW, unbelievable! that worked perfectly! where did u get that code? i googled all over the place and was unable to find ANYTHING. thanks a lot!

cheers,
nate
That is the standard Office File Dialog code with slight modifications.
Jun 20 '08 #4
i have a quite similar problem. where should i paste the codes? is it under the cmdBrowse_Click()?? i've tried it but there is a run time error occured. (sorry, i am a beginner in programming)
Aug 5 '10 #5
EADJLT
1
This code does not work in access 2013. I have been looking a couple a days for the right code and thought I found it.

I want to browse and select a file en then save the path of te file to a textbox. The saved data in the textfield must be saved in a field in a table.

Can you help me?
Jan 24 '14 #6
ADezii
8,834 Expert 8TB
This code does not work in access 2013
  1. What exactly do you mean when you say it doesn't work, are you getting any Error Messages?
  2. Did you set a Reference to the Microsoft Office XX.X Object Library?
Jan 24 '14 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
5
by: Jon D | last post by:
I have a form where a user enters their name, date etc. i also want them to be able to click on a browse button and select a file which will then appear in a textbox. when they press submit i want...
4
by: Dave N | last post by:
I want to programatically open the Access "File" "Open" browse box to search for a file. When it is selected I wnat to have it put the path in a text box so it can be added to a list box.
5
by: deko | last post by:
I'm using the below code to allow users to browse for and select a folder. After selecting a folder from the dialog, the full path is returned to a text box and saved. The next time the user...
18
by: walterbyrd | last post by:
I am trying to develop an app where: the same file, in the same place, will be uploaded, and then processed. Everything I can find about uploading a file, uses a form that requires the user to...
3
by: Highlander | last post by:
Hello all. Consider the following HTA: <HTML> <HEAD> <TITLE></TITLE></HEAD> <BODY> <SCRIPT LANGUAGE="VBScript"> Sub ButBrowse_onclick() '-- show browse window and Get file path:
4
by: DMG | last post by:
I have <identity impersonate = "true" /& <authentication mode="Windows"/in the web.config. This is a 2.0 site. My Goal: I want to simply have the user browse to a file on a mapped drive and get...
4
by: developing | last post by:
Hi All, I have a browse button that the user can click to select a file. The button then fetches the file path. This is all working fine except my boss wants some add functionality. I need it to...
1
by: developing | last post by:
Hello, This time I want to filter the 'browse for file' API so that certain drives/folders cant be accessed. Not sure how to go about this...here is the module I am currently using to browse...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.