?
Solved

Select Excel File for Import with Form Button

Posted on 2014-11-04
4
Medium Priority
?
1,422 Views
Last Modified: 2014-11-04
With Access 2007, I have successfully used this code in the past to open a Browse... window for importing Excel files with a form button.


Private Sub SelectSurvey_Click()

    Dim strStartDir As String
    
    Dim strFilter As String
    Dim lngFlags As Long
    
    ' Lets start the file browse from our current directory
     
    strStartDir = CurrentDb.Name
    strStartDir = Left(strStartDir, Len(strStartDir) - Len(Dir(strStartDir)))

    
    strFilter = ahtAddFilterItem(strFilter, _
                        "Excel Files (*.xls)", "*.xls")
    Me.txtFileName = ahtCommonFileOpenSave(InitialDir:=strStartDir, _
                     Filter:=strFilter, FilterIndex:=3, flags:=lngFlags, _
                     DialogTitle:="Select File")
        

End Sub

Open in new window


However, I am now using Access 2010 and I receive the error "Method or data member not found" in association with "txtFileName".

I am not sure if it is the newer version of Access (or something else) that is causing this.

Does anyone have a suggestion for how to get this function working? I am willing to try a whole new set of code if that is what will be necessary.
0
Comment
Question by:dougf1r
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 85
ID: 40422993
Are you sure you have the necessary functions to use this code? For example, you must have a function named ahtCommonFileOpenSave in a Standard Module.

See this link for more information: http://access.mvps.org/access/api/api0001.htm
0
 

Expert Comment

by:gracie1972
ID: 40423003
I would try to import the spreadsheet first (You can delete after) then save the import name as "ahtCommonFileOpenSave" at the last step (check Save Import Steps).  I had that same issue before and that was a work around.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40423013
do you have a textbox named "txtFileName " in your form?

you can also try this codes
*you need to add Microsoft Office 14.0 object library to your references
* you also need textbox named "txtFileName "


Private Sub SelectSurvey_Click()

Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
    .Filters.Clear
    .Filters.Add "Microsoft Excel", "*.xls,*.xlsx"
    .Title = "Select Excel file"
    .InitialFileName = CurrentProject.Path & "\"
    .AllowMultiSelect = False
    
    If .Show Then
        Me.txtFileName = .SelectedItems(1)
    End If
    

End With
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:dougf1r
ID: 40423045
Indeed, I had forgotten to bring over the textbox named "txtFileName". I added that back in and it works now.

Thanks Rey!
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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