473,406 Members | 2,707 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,406 software developers and data experts.

Allow user to choose a file path in access vba code

1
Hi,
I am trying to declare a variable as a FileDialog object in VB for MS Access 2007

Dim fd As FileDialog

But, I am receiving an error message “ Compiler error : User-Defined type not defined”

I already checked the reference and checked the box mcrosoft office 12.0 access database engine object library.
But still i am getting the same error msg
Can you please help here?
what is the appropriate VBA reference to the Microsoft Office 2007 Object library
my code is here

Expand|Select|Wrap|Line Numbers
  1. Sub Main()
  2.  
  3.     'Declare a variable as a FileDialog object.
  4.     Dim fd As FileDialog
  5.  
  6.     'Create a FileDialog object as a File Picker dialog box.
  7.     Set fd = Application.FileDialog(msoFileDialogFilePicker)
  8.  
  9.     'Declare a variable to contain the path
  10.     'of each selected item. Even though the path is a String,
  11.     'the variable must be a Variant because For Each...Next
  12.     'routines only work with Variants and Objects.
  13.     Dim vrtSelectedItem As Variant
  14.  
  15.     'Use a With...End With block to reference the FileDialog object.
  16.     With fd
  17.  
  18.         'Use the Show method to display the File Picker dialog box and return the user's action.
  19.         'The user pressed the action button.
  20.         If .Show = -1 Then
  21.  
  22.             'Step through each string in the FileDialogSelectedItems collection.
  23.             For Each vrtSelectedItem In .SelectedItems
  24.  
  25.                 'vrtSelectedItem is a String that contains the path of each selected item.
  26.                 'You can use any file I/O functions that you want to work with this path.
  27.                 'This example simply displays the path in a message box.
  28.                 MsgBox "The path is: " & vrtSelectedItem
  29.  
  30.             Next vrtSelectedItem
  31.         'The user pressed Cancel.
  32.         Else
  33.         End If
  34.     End With
  35.  
  36.     'Set the object variable to Nothing.
  37.     Set fd = Nothing
  38.  
  39. End Sub


Expand|Select|Wrap|Line Numbers
  1. Public Sub cmdSelect_Click()
  2. Main
  3. End Sub
Feb 7 '14 #1
2 5180
Luk3r
300 256MB
From another bytes.com thread with the same issue:
http://bytes.com/topic/access/answer...pe-not-defined
Feb 7 '14 #2
zmbd
5,501 Expert Mod 4TB
For other's looking having similar issues.
Allen Browne has a cross reference table for which version to use for which version of Office you have installed Solving Problems with Library References The table is towards the bottom of this link.

Please do not use the older versions of these files with your newer applications. These are provided for legacy support only and can result in some very unusual issues.

The method to add these references is the same since 2003 so here's the 2010:
Check or Add an Object Library Reference Office 2010

You should also refer to this insights article:
Select a File or Folder using the FileDialog Object This code has been reviewed and used by a great number of people.
Feb 7 '14 #3

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

Similar topics

3
by: Dave Y | last post by:
Hello, I am new to ASP as well as IIS. I am trying to learn how to create a web application using asp.NET. I have followed the instructions for configuring the IIS settings but when I click on...
2
by: B Garrett | last post by:
Hi, I have a .ASPX page using C# and I need to read in a text file from a selected path. so in need the file dialog box to allow the user to choose the path and file that they want to read in. ...
1
by: Dave | last post by:
I've built a custom server control that reads an xml file and builds a left side navigation system. When I drop that server control into a user control that will hold the left side navigation for...
2
by: mosaic.com | last post by:
I don't know who to go with for this question, googling is not very helpful, if anyone has an idea i would appreciate it. The issue: I created a page that will be used as a template for HTML...
3
by: den 2005 | last post by:
Hi everybody, I like to allow user to select and browse to which location to save the pdf file of a crystal report viewed on a web page, how can i do this in ASP.Net? I need to get the path...
3
by: Vibhu | last post by:
Hello All, I have a input box on the HTML page with the type set to file. What I want is that when the value changes in the file textbox, it should give me the full file path. I have even tried...
3
by: Stephan | last post by:
Hi all, I am new to access and I face the following "issue": I would like to create a database, to which users can upload files (=pdf, doc, xls...). The files shall be stored locally on a...
9
by: Quiver | last post by:
Is there a way to have the user choose what file to import, but set everything else up in VBA? The command button that would start the import would have something like this -- ...
2
by: mpalomas | last post by:
Hi C++ folks, I have trouble to open files whose path contains non-ascii characters with std::ifstream. For instance let's say i just have a file which has Japanese characters either in the...
10
by: Raheem | last post by:
Hello, I built a development version of a live website on my hosted account. However the development version is having problems with finding include files. After troubleshooting I was able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.