Solved

Select file for upload from browser in access2010

Posted on 2013-12-19
5
323 Views
Last Modified: 2014-09-13
I have code that let's the user select files from the browser but then populates a list box  but I need to have the user only select ONE file, have this populate a text box on the form and then use this to be passed into the procedure to Import an excel worksheet.  My attempts to change the excising code do not work, so any suggestions on how to go about this would be appreciated.  Normally I would do research, but. Y deadline is too tight.

Sandra
0
Comment
Question by:ssmith94015
5 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 39730427
This code works in access 2010 as well as earlier versions of Access:

http://access.mvps.org/access/api/api0001.htm

Place the code in a standard module, and look for the function "TestIt", which shows you how to call the file dialog function, and get the user selected filename.
0
 
LVL 31

Assisted Solution

by:Helen_Feddema
Helen_Feddema earned 250 total points
ID: 39732435
This code lets you select a file; after getting the file name, you can write it to a textbox, export it to Excel, or whatever:

Public Function SelectFile() As String
'Requires Office XP (2002) or higher
'Requires a reference to the Microsoft Office Object Library
'Created by Helen Feddema 3-Aug-2009
'Last modified 3-Aug-2009
'Word, Access and Excel have a FileDialog property of their Application
'object; Outlook does not

On Error GoTo ErrorHandler

   Dim fd As Office.FileDialog
   Dim varSelectedItem As Variant
   Dim strFileNameAndPath As String
   
   'Create a FileDialog object as a File Picker dialog box.
   Set fd = Application.FileDialog(msoFileDialogFilePicker)
   
   With fd
      'Set AllowMultiSelect to True to allow selection of multiple files
      .AllowMultiSelect = False
      .Title = "Browse for File"
      .ButtonName = "Select"
      .Filters.Clear
      'Modify filters as needed
      .Filters.Add "Documents", "*.doc; *.txt", 1
      .InitialView = msoFileDialogViewDetails
      If .Show = -1 Then
         'Get selected item in the FileDialogSelectedItems collection
         For Each varSelectedItem In .SelectedItems
            strFileNameAndPath = CStr(varSelectedItem)
         Next varSelectedItem
      Else
         Debug.Print "User pressed Cancel"
         strFileNameAndPath = ""
      End If
   End With
   
   SelectFile = strFileNameAndPath
   
ErrorHandlerExit:
   Set fd = Nothing
   Exit Function

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & " in SelectFile procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit

End Function

Open in new window

0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39735949
I used to use the API call provided by mbizup, but now use the Office.FileDialog method used in Helen's example;  I find it easier to use.
0
 

Author Comment

by:ssmith94015
ID: 39736775
I have not forgotten this, am trying suggestions amid system crisis eps!
0
 

Author Closing Comment

by:ssmith94015
ID: 40320957
Both were useful.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question