retrieve filename form windows explorer

  • Thread starter Thread starter Michel Peeters
  • Start date Start date
M

Michel Peeters

With the start options (command or macro) from Access I want to start the
import of a selected file in the windows explorer window.
I made a short cut to a " *.bat file " that starts Access and starts a
macro >function>call import procedure.
I placed this short cut in the "send to" menu so that the Access application
can start fthrough a right mouse click from the window explorer.
My problem: How do I retrieve the selected file - and pathname?

Tks
Michel
 
I have a question regarding this...

the code from the link that you provided... where would that go? would a
new module need to be created? then a command button?

Brook
 
The code should be placed in a new blank module. Save the module with a name
like: basAPIs.

There is sample code that would call the function. You could place your code
in the On Click event of a command button.
 
hello Duane,

OK i'm looking at the code from the link and I created a new module called
basAPIs per your instructions and pasted the code from the link that was
between the :

************** Code Start **************
code...
************** Code End *****************

But I'm unsure how to call it or what to do with the other code that is
provided ... ie what is below:

Thanks,

Brook


begin code ***
Dim strFilter As String
Dim strInputFileName as string

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
end code ***

begin code ***
Ask for SaveFileName
strFilter = ahtAddFilterItem(myStrFilter, "Excel Files (*.xls)", "*.xls")
strSaveFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)
end code ***
 
The code you posted is not complete. Below is a full example of how to
retrieve the path and filename of the selected file. You would put this
where you need to use it. For example, in the Click event of a command button
you would use to begin an import or an export, or however you intend to use
the file:

'Set filter to show only Excel spreadsheets
strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)")
'Hides the Read Only Check Box on the Dialog box
lngFlags = ahtOFN_HIDEREADONLY

strCurrMonth = Me.cboPeriod.Column(1)
strCurrYear = Me.txtCurrYear
'Get the File Name To Save
strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" &
strCurrYear _
& " Actuals\" & strCurrMonth & "\"
varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear &
".xls"

varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _
strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _
"xls", varGetFileName, "Import Adjusted Actuals", , True)
Me.Repaint
If varGetFileName = "" Then 'User Clicked CANCEL
GoTo LoadAdjustedActuals_Exit
End If
 
ok... so I posted the code into a command buttons properties... but I am
getting an error...

Compile Error:

Method or Data member not found.

Private Sub Command0_Click()
Dim strFilter As String
Dim strInputFileName As String
'Set filter to show only Excel spreadsheets
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)")
'Hides the Read Only Check Box on the Dialog box
lngFlags = ahtOFN_HIDEREADONLY

strCurrMonth = Me.cboPeriod.Column(1) *** error....
strCurrYear = Me.txtCurrYear
'Get the File Name To Save
strDefaultDir = "c:\ " & strCurrYear & "\" & strCurrYear _
& " Actuals\" & strCurrMonth & "\"
varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls"

varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _
strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _
"xls", varGetFileName, "Import Adjusted Actuals", , True)
Me.Repaint
If varGetFileName = "" Then 'User Clicked CANCEL
GoTo LoadAdjustedActuals_Exit
End If

End Sub


Do I need to make changes to import a .txt file or a .csv file?

Brook
 
If you are getting method or data member not found, some variable is not
declared (Dim). The code example I sent does not include all the
declarations because they are declared at the module level. Also, there are
some references to controls on my form you will have to change.

As to importing .cvs or .txt files, you can put them where I have .xls

Dim varGetFileName As Variant 'Pass to Common Dialog to open workbook
Dim strCurrMonth As String 'Used to build file name to open
Dim strCurrYear As String 'Used to build file name to open
Dim strDefaultDir As String 'Pass Directory to search for common dialog
Dim strfilter As String 'Limit common dialog search to excel workbooks
Dim lngFlags As Long 'Hide readonly check box on common dialog
 
Back
Top