473,466 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Prompt user to search for file to import using macro actions

22 New Member
I am creating a form to do a variety of things, but the first step is to import a file from Excel into an existing table. I know this can be done using the 'TransferSpreadsheet' action. However, the file name will be different each time.

Is there a command or something that can be entered into the 'file name' argument for this action that will allow the user to browse for the file to be imported?
May 15 '07 #1
9 12095
ADezii
8,834 Recognized Expert Expert
I am creating a form to do a variety of things, but the first step is to import a file from Excel into an existing table. I know this can be done using the 'TransferSpreadsheet' action. However, the file name will be different each time.

Is there a command or something that can be entered into the 'file name' argument for this action that will allow the user to browse for the file to be imported?
Yes, but how to go about this depends on your Access Version. What Version of Access are you running?
May 15 '07 #2
kickergirl
22 New Member
Yes, but how to go about this depends on your Access Version. What Version of Access are you running?

I am using Access2000.
May 15 '07 #3
Denburt
1,356 Recognized Expert Top Contributor
You will need to set a reference in VBA (tools-References) then find and click on "Microsoft Office" to use this.
Expand|Select|Wrap|Line Numbers
  1. Dim myDialog As FileDialog
  2. Dim strFile As String
  3. Dim strSearchPath as string
  4. Dim vrtSelectedItem As Variant
  5. Set myDialog = Application.FileDialog(msoFileDialogOpen)
  6. 'Use strSearchPath  if you want to start in a particular directory. You can leave it out if you wish (as I have it commented out right now) and it will start with a default directory of Windows choosing.
  7. 'strSearchPath ="C:\SomeDirectory\SomeSubDirectory"
  8. With myDialog
  9.     .AllowMultiSelect = True
  10.      .Filters.Add "Excel Files", "*.xls", 1
  11.     .Title = "Please Locate the Files to Import!"
  12.     .InitialFileName = strSearchPath
  13.      If .Show = -1 Then
  14.  
  15.     For Each vrtSelectedItem In .SelectedItems
  16.       'I pass the file information to another routine that handles the transfer  
  17.       ImportIt (vrtSelectedItem)
  18.     Next vrtSelectedItem
  19.         MsgBox "All data imported into the NewData Table." & vbCrLf & vbCrLf & "We will now post any new data into the data table!"
  20.         Else
  21.         'The user pressed Cancel.
  22.         End If
  23.    Set myDialog = Nothing
  24. End With
May 15 '07 #4
kickergirl
22 New Member
You will need to set a reference in VBA (tools-References) then find and click on "Microsoft Office" to use this.
Expand|Select|Wrap|Line Numbers
  1. Dim myDialog As FileDialog
  2. Dim strFile As String
  3. Dim strSearchPath as string
  4. Dim vrtSelectedItem As Variant
  5. Set myDialog = Application.FileDialog(msoFileDialogOpen)
  6. 'Use strSearchPath  if you want to start in a particular directory. You can leave it out if you wish (as I have it commented out right now) and it will start with a default directory of Windows choosing.
  7. 'strSearchPath ="C:\SomeDirectory\SomeSubDirectory"
  8. With myDialog
  9.     .AllowMultiSelect = True
  10.      .Filters.Add "Excel Files", "*.xls", 1
  11.     .Title = "Please Locate the Files to Import!"
  12.     .InitialFileName = strSearchPath
  13.      If .Show = -1 Then
  14.  
  15.     For Each vrtSelectedItem In .SelectedItems
  16.       'I pass the file information to another routine that handles the transfer  
  17.       ImportIt (vrtSelectedItem)
  18.     Next vrtSelectedItem
  19.         MsgBox "All data imported into the NewData Table." & vbCrLf & vbCrLf & "We will now post any new data into the data table!"
  20.         Else
  21.         'The user pressed Cancel.
  22.         End If
  23.    Set myDialog = Nothing
  24. End With
Thank you!
May 15 '07 #5
Denburt
1,356 Recognized Expert Top Contributor
Thank you!
You are quite welcome.
May 15 '07 #6
bae14
9 New Member
Is this process different for Access 97? How do I "use" this once it is created? I would like to use this on a form where a user would click on a button and have it prompt to import a file. Thanks!
May 22 '07 #7
webcat
13 New Member
i need to do the same thing in Access 2003 (and it must work in 2007 as well)

does anyone know exactly how to link this VB into a macro to enable me to import an excel sheet which could be anywhere on someones system...?

thanks
Jun 7 '07 #8
ADezii
8,834 Recognized Expert Expert
Is this process different for Access 97? How do I "use" this once it is created? I would like to use this on a form where a user would click on a button and have it prompt to import a file. Thanks!
  1. This code would not work in Access 97, since the FileDialog Object does not exist.
  2. To demo how Denburt's code could be used, I've displayed a small segment of code, simply insert it where appropriate. It is listed below:
    Expand|Select|Wrap|Line Numbers
    1. Dim strFilePath As String
    2.  
    3. If .Show = -1 Then
    4.   For Each vrtSelectedItem In .SelectedItems
    5.     'There will only be 1 Item in the Collection since
    6.     'MultiSelect should be set to False in this case
    7.     strFilePath = vrtSelectedItem
    8.   Next vrtSelectedItem
    9. Else
    10.   'The user pressed Cancel.
    11.    Exit Sub
    12. End If
    13.  
    14. DoCmd.TransferSpreadsheet acImport, <excel version>, <table name>, strFilePath, <has field names>
Jun 7 '07 #9
Denburt
1,356 Recognized Expert Top Contributor
File Dialog using API Functions

Took a little digging but I found an article for Acc97.

Try this and let us know how it turns out for you.

http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx

If I am not mistaken one of the samples for Acc97 has this or similar code in their database for refreshing table links.
Jun 7 '07 #10

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

Similar topics

3
by: ^CeFoS^ | last post by:
Hi to everybody, due to I want to use the serial port of a server machine through an applet allocated in html document. > Then one application will run in the server machine and using > the serial...
79
by: pinkfloydhomer | last post by:
I want to scan a file byte for byte for occurences of the the four byte pattern 0x00000100. I've tried with this: # start import sys numChars = 0 startCode = 0 count = 0
8
by: David Horsman | last post by:
I have a report that lists File-B. My macro runs this report using a query as a filter. The query uses two files, the parent File-B and with a 0-many relationship to File-C. The query selects...
6
by: Robert Pettersson | last post by:
Hi, I have built an webapp in C# that uses SMTPMail to send mail to users. When I installed it on the prodserver everything worked fine for me, but the users can not send mail. They get Access...
0
by: Paul M | last post by:
Hello, I need to examine the contents of a macro (ie the step it executes and their comments). I can look in the scripts (macros) collection but can't see the macros actions & comments (and any...
2
by: kmarchiony | last post by:
Hi anyone! I am working to translate an Excel macro into Access and I'm having little luck with a couple lines of code. I can't figure out how to prompt the user to select a file (not to past a...
6
by: AZRebelCowgirl73 | last post by:
Here is my problem: I have two java files: One named Car.java and the other named CarDealerApp.java: In the CarDealerApp program, I read in through user input the make, model, year and price of...
1
by: Roy | last post by:
Hi all, Thanks for your replies.I have to develop an application which will read a .DAT file.There are several hundred records in this file.Also I get another excel file with adds and deletes....
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.