473,761 Members | 8,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Allow user to choose what file to import

9 New Member
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 --

Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel9, "tblMAIN",???,True
-- with the ??? indicating where you would typically put the path and name of the spreadsheet. However, the spreadsheet that will be imported will have a variable name including the date (such as "IMPORT080807.x ls").

Any thoughts on how to do this?

Thanks!
Aug 8 '07 #1
9 19171
Rabbit
12,516 Recognized Expert Moderator MVP
You could use the filedialog class to open up a Select File Dialog where they navigate to the file they want.
Aug 8 '07 #2
Sysdupe123
4 New Member
Here is a way you can have a browser window pop up and they can select the file, regardless of the name or filepath.

Function GetFile()
'Declare a variable to contain FileDialog
Dim sMyPath As FileDialog
'Declare a variable to contain the path
Dim sPath As Variant


DoCmd.SetWarnin gs False
DoCmd.Hourglass True
' Set up the File Dialog.

Set sMyPath = Application.Fil eDialog(msoFile DialogFilePicke r)

With sMyPath

' Allow users to not make multiple selections in dialog box
.AllowMultiSele ct = False

' Set the title of the dialog box.
.Title = "Select your File"

' Clear out the current filters, and add your own.
.Filters.Add "All Files", "*.*"

'Set the text of the button Caption
'.strButtonCapt ion = "Get File"

'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
For Each sPath In .SelectedItems

'import into primary table
DoCmd.TransferS preadsheet acImport, "tblName", "Equipment" , sPath, True
Next sPath
Else
'Show if Canceled is selected in a message box
sPath = "No File Selected to Import."
MsgBox sPath
End If

End With
DoCmd.SetWarnin gs True
DoCmd.Hourglass False


End Function

If you are setting up a form, you can direct a command button to this function and the user can import the file.
Aug 8 '07 #3
Quiver
9 New Member
It won't compile. It freezes on "Dim sMyPath As FileDialog". FileDialog is not an option. Do I need to reference a specific library? I'm using Access 2000 with VB 6.5.

Thanks.
Aug 8 '07 #4
Rabbit
12,516 Recognized Expert Moderator MVP
Access 2000... I don't think FileDialog came with Access 2000. It started with Office XP and up.
Aug 8 '07 #5
Quiver
9 New Member
Thanks Sysdupe123 and Rabbit.

I was bummed to hear about FileDialog not being available on A2K.

I ended up using something like this...

Expand|Select|Wrap|Line Numbers
  1. Dim strDate as string
  2. strDate = InputBox("What is the date on the import file?", , "mm-dd-yyyy")
  3.  
  4. DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel9, "tblMAIN","IMPORT_" & strDate & ".xls",True
This got the job done.

Thanks again!
Aug 10 '07 #6
jschmidt
47 New Member
Thanks Sysdupe123 and Rabbit.

I was bummed to hear about FileDialog not being available on A2K.

I ended up using something like this...

Expand|Select|Wrap|Line Numbers
  1. Dim strDate as string
  2. strDate = InputBox("What is the date on the import file?", , "mm-dd-yyyy")
  3.  
  4. DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel9, "tblMAIN","IMPORT_" & strDate & ".xls",True
This got the job done.

Thanks again!
Sorry about this post. It was double posted so I removed this one.
Aug 10 '07 #7
jschmidt
47 New Member
Thanks Sysdupe123 and Rabbit.

I was bummed to hear about FileDialog not being available on A2K.

I ended up using something like this...

Expand|Select|Wrap|Line Numbers
  1. Dim strDate as string
  2. strDate = InputBox("What is the date on the import file?", , "mm-dd-yyyy")
  3.  
  4. DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel9, "tblMAIN","IMPORT_" & strDate & ".xls",True
This got the job done.

Thanks again!
You could use the file dialog if you set a reference to Microsoft Office 11 Object library (11 or Higher). You can do this in your vbscript editor by clicking tools/references and then find the object library from the list. But it looks like you figured something else out. Good Luck.
Aug 10 '07 #8
Quiver
9 New Member
Thanks for the idea. I actually just tried setting the reference to the Microsoft Office 11.0 Object Library (as a learning experience :) and it still can't find it when I debug.
Aug 10 '07 #9
Krunchy
2 New Member
I'm having the same kind of issue I have the file on the desktop of the users computer it's the same place that they will have their mini database.
It seems to not be able to find the file it give me the error msg I have put in everytime. If I need the whole path the login of the user has to be entered by them. Thats the reason for the inputbox section.
Expand|Select|Wrap|Line Numbers
  1. Function Importfile()
  2.  
  3. Dim login As String
  4. On Error GoTo Err_Importfile
  5. 'login = InputBox("What is your LAN ID?")
  6.  
  7. DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tracker", "trackerimport.xls", True
  8.  
  9. Exit_Importfile:
  10.     Exit Function
  11.  
  12. Err_Importfile:
  13.     MsgBox "Tracker File is not found. Please save sales tracker export to desktop and as trackerimport.xls and try importing again"
  14.     Resume Exit_Importfile
  15. End Function
  16.  
Aug 17 '07 #10

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

Similar topics

2
3939
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company 1&1 with only limited server configuration via a web based control panel. My query relates to the ASP security model and how it relates to FrontPage options for setting file access on a database file. If you know of any online documentation...
2
631
by: todd | last post by:
Hi all. I inherited this code from a contractor. It is a .NET user control that runs on the client side (ie) on machines with the framework installed. I have been mucking around to get it work for a couple of days now, and am growign really frustrated. I need to expose an Import method on the ImportControl and have it accesible to javascrip in the browser. If I remove the InterfaceType and ClassInterface attributes, compile and then...
4
2460
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item, what do I need to do in order to return the "option value" of the control? Moe !--- returned value of the control
10
18933
by: Bishman | last post by:
Hi, I need to programmatically allow or disallow the selection of multiple checkboxes on a form . At certain times I only want to allow a single selection, at other times I may wish to allow multiple. Is there a way of doing this ? I dont want to use Radio buttons..... Thanks,
34
2319
by: samjnaa | last post by:
This is like the previous one. Please check for sanity and approve for posting at python-dev. I would like to have something like "option base" in Visual Basic. IIRC it used to allow me to choose whether 0 or 1 should be used as the base of member indices of arrays. In Python, the same can be used with strings, lists, tuples etc. This would mean: foo = "foo"
8
2384
by: Alan Isaac | last post by:
Suppose I have a directory `scripts`. I'd like the scripts to have access to a package that is not "installed", i.e., it is not on sys.path. On this list, various people have described a variety of tricks they use, but nobody has proposed a pretty way to allow this. I am therefore assuming there is not one. (?) How about allowing a `scripts.pth` file in such a `scripts` directory, to work like a path configuration file?
1
1236
by: hr833 | last post by:
I'm creating an interface for some staff. I was wondering whether it is possible to allow the user to map the file to import. Bause now i'm using a marco action to import the file and the file specifcally mapped by me.. so the all users must used that specific file only...It's rather erm troublesome/stupid... PLEASE PLEASE AND THANK YOU
2
1379
by: Larry Bud | last post by:
I've got some SQL data file of names/addresses that I would like to import on a daily basis into the FedEx.com website's address book. If you have a FedEx account (like our company does), you can manually do an import of a CSV file. I would like to eliminate manual intervention into this. We don't signup for the FedEx software to run locally (which from what I understand, they have an API to interact with). So the only solution I...
1
4986
by: whitep8 | last post by:
Hi all, im attempting to make a user menu, which the user instigates the exit, not netbeans. basically i want a menu displayed, user makes selection, that specific piece is ran, on completion the user is returned to the main menu. The following is my attempt, however its not doing what i need. i get no errors
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.