| DatabaseLessons.com |
'Serving the Microsoft® Access |
|
|
Choosing a File from a ListI built an application recently that needed to present the user with a list of Excel file templates to choose from. The program then filled in the necessary data, using techniques from my "Sending Data to Excel" series (coming soon!). (article continues after sponsor spot) The list of available files was presented in a list box, and the user clicked on the one they wanted. The steps I took were:
The first time you use the Dir function in Access VBA, it requires a file name (or wildcard version) as well as the folder (directory) path. If using a wildcard, then the subsequent calls to Dir will return the next file that matches. When there are no more files, the function returns an empty string. Here is the code that I used. NOTE: All the VBA code segments on the Database Lessons site assume that you have DAO references active. If you are not sure what this means, and you are using Microsoft Access 2000 or higher, click here. Dim MyFile As String Further Suggestions: In the original application that I created, the templates are actually in the same folder as the database, so I have VBA code that determines the name of the folder and use that instead of the hard-coded "C:\MyExcelTemplates\". Happy Coding |
|
|
© 2006, 2007, 2008 Richard W. Killey. All Rights Reserved. - Privacy Policy |