Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Select file for upload from browser in access2010

Posted on 2013-12-19
5
Medium Priority
?
362 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 1000 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 1000 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 49

Expert Comment

by:Dale Fye
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

782 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