473,387 Members | 1,799 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,387 software developers and data experts.

Allow user to choose what file to import

9
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.xls").

Any thoughts on how to do this?

Thanks!
Aug 8 '07 #1
9 19090
Rabbit
12,516 Expert Mod 8TB
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
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.SetWarnings False
DoCmd.Hourglass True
' Set up the File Dialog.

Set sMyPath = Application.FileDialog(msoFileDialogFilePicker)

With sMyPath

' Allow users to not make multiple selections in dialog box
.AllowMultiSelect = 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
'.strButtonCaption = "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.TransferSpreadsheet 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.SetWarnings 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
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 Expert Mod 8TB
Access 2000... I don't think FileDialog came with Access 2000. It started with Office XP and up.
Aug 8 '07 #5
Quiver
9
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
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
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
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
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
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...
2
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...
4
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,...
10
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...
34
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...
8
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...
1
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...
2
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...
1
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.