What Piet's given you is NOT sufficient. If you look, you'll see it's only
part of the code at
http://www.mvps.org/access/api/api0001.htm
Go to the webpage you cited and copy everything in the shaded area (between
Code Starts and Code Ends) and paste it into a new code module (not a class
module nor a module associated with a form or report). Save the module,
making sure you give it a unique name (modules cannot have the same name as
functions or subs contained in the application. For this reason, many people
choose to prefix all their module names with bas or mod, and then not use
that prefix anywhere else).
To present the user with the dialog and capture his/her choice into variable
strInputFile, you'd then use the following code:
Dim strFilter As String
Dim strInputFileName as string
strFilter = ahtAddFilterItem(strFilter, "Comma-Separated Value Files
(*.csv)", "*.csv")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
I would like the user to click a button that would open the import dialog
box
to CurrentProject.Path with csv already selected as the file type. The
user
could then select a particular csv file. (The csv file name will change
from
time to time or there could be more than one). This question was asked and
answered a couple of years ago and the MVP directed the asker
tohttp://
www.mvps.org/access/api/api0001.htm. I tried what I thought
applied,
but, after many tries, had to give up. Very likely beyond my capability to
extract relevant code. . I use Access2000 with Windows 2000. Any help will
be much appreciated. Thanks in advance
Function GetOpenFile(Optional varDirectory As Variant, _
Optional varTitleForDialog As Variant) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
lngFlags = ahtOFN_FILEMUSTEXIST Or _
ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR
If IsMissing(varDirectory) Then
varDirectory = ""
End If
If IsMissing(varTitleForDialog) Then
varTitleForDialog = ""
End If
' Define the filter string and allocate space in the "c"
' string Duplicate this line with changes as necessary for
' more file templates.
'strFilter = ahtAddFilterItem(strFilter, _
"Access (*.mdb)", "*.MDB;*.MDA")
strFilter = ahtAddFilterItem(strFilter, "Comma-separated values
(*.csv)", "*.CSV")
' Now actually call to get the file name.
varFileName = ahtCommonFileOpenSave( _
OpenFile:=True, _
InitialDir:=varDirectory, _
Filter:=strFilter, _
Flags:=lngFlags, _
DialogTitle:=varTitleForDialog)
If Not IsNull(varFileName) Then
varFileName = TrimNull(varFileName)
End If
GetOpenFile = varFileName
End Function
Call:
?GetOpenFile(currentproject.Path,"Choose a CSV file...")
or probably...
strFile = GetOpenFile(currentproject.Path,"Choose a CSV file...")