Solved

Select Excel File for Import with Form Button

Posted on 2014-11-04
4
1,373 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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

724 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