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 -- - 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!
9 19090
You could use the filedialog class to open up a Select File Dialog where they navigate to the file they want.
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.
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.
Access 2000... I don't think FileDialog came with Access 2000. It started with Office XP and up.
Thanks Sysdupe123 and Rabbit.
I was bummed to hear about FileDialog not being available on A2K.
I ended up using something like this... - Dim strDate as string
-
strDate = InputBox("What is the date on the import file?", , "mm-dd-yyyy")
-
-
DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel9, "tblMAIN","IMPORT_" & strDate & ".xls",True
This got the job done.
Thanks again!
Thanks Sysdupe123 and Rabbit.
I was bummed to hear about FileDialog not being available on A2K.
I ended up using something like this... - Dim strDate as string
-
strDate = InputBox("What is the date on the import file?", , "mm-dd-yyyy")
-
-
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.
Thanks Sysdupe123 and Rabbit.
I was bummed to hear about FileDialog not being available on A2K.
I ended up using something like this... - Dim strDate as string
-
strDate = InputBox("What is the date on the import file?", , "mm-dd-yyyy")
-
-
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.
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.
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. -
Function Importfile()
-
-
Dim login As String
-
On Error GoTo Err_Importfile
-
'login = InputBox("What is your LAN ID?")
-
-
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tracker", "trackerimport.xls", True
-
-
Exit_Importfile:
-
Exit Function
-
-
Err_Importfile:
-
MsgBox "Tracker File is not found. Please save sales tracker export to desktop and as trackerimport.xls and try importing again"
-
Resume Exit_Importfile
-
End Function
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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,...
| |