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?
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?
Yes, but how to go about this depends on your Access Version. What Version of Access are you running?
I am using Access2000.
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. - Dim myDialog As FileDialog
-
Dim strFile As String
-
Dim strSearchPath as string
-
Dim vrtSelectedItem As Variant
-
Set myDialog = Application.FileDialog(msoFileDialogOpen)
-
'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.
-
'strSearchPath ="C:\SomeDirectory\SomeSubDirectory"
-
With myDialog
-
.AllowMultiSelect = True
-
.Filters.Add "Excel Files", "*.xls", 1
-
.Title = "Please Locate the Files to Import!"
-
.InitialFileName = strSearchPath
-
If .Show = -1 Then
-
-
For Each vrtSelectedItem In .SelectedItems
-
'I pass the file information to another routine that handles the transfer
-
ImportIt (vrtSelectedItem)
-
Next vrtSelectedItem
-
MsgBox "All data imported into the NewData Table." & vbCrLf & vbCrLf & "We will now post any new data into the data table!"
-
Else
-
'The user pressed Cancel.
-
End If
-
Set myDialog = Nothing
-
End With
You will need to set a reference in VBA (tools-References) then find and click on "Microsoft Office" to use this. - Dim myDialog As FileDialog
-
Dim strFile As String
-
Dim strSearchPath as string
-
Dim vrtSelectedItem As Variant
-
Set myDialog = Application.FileDialog(msoFileDialogOpen)
-
'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.
-
'strSearchPath ="C:\SomeDirectory\SomeSubDirectory"
-
With myDialog
-
.AllowMultiSelect = True
-
.Filters.Add "Excel Files", "*.xls", 1
-
.Title = "Please Locate the Files to Import!"
-
.InitialFileName = strSearchPath
-
If .Show = -1 Then
-
-
For Each vrtSelectedItem In .SelectedItems
-
'I pass the file information to another routine that handles the transfer
-
ImportIt (vrtSelectedItem)
-
Next vrtSelectedItem
-
MsgBox "All data imported into the NewData Table." & vbCrLf & vbCrLf & "We will now post any new data into the data table!"
-
Else
-
'The user pressed Cancel.
-
End If
-
Set myDialog = Nothing
-
End With
Thank you!
Denburt 1,356
Recognized Expert Top Contributor
Thank you!
You are quite welcome.
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!
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
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!
- This code would not work in Access 97, since the FileDialog Object does not exist.
- 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:
- Dim strFilePath As String
-
-
If .Show = -1 Then
-
For Each vrtSelectedItem In .SelectedItems
-
'There will only be 1 Item in the Collection since
-
'MultiSelect should be set to False in this case
-
strFilePath = vrtSelectedItem
-
Next vrtSelectedItem
-
Else
-
'The user pressed Cancel.
-
Exit Sub
-
End If
-
-
DoCmd.TransferSpreadsheet acImport, <excel version>, <table name>, strFilePath, <has field names>
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
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: 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...
|
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 ...
| |