Other Topics > Smart Access 1996-2006 > Jun-2003 > Replace Your File API’s With The FileDialog Object

Replace Your File API’s With The FileDialog Object  

<< Click to Display Table of Contents >>

Navigation:  Other Topics > Smart Access 1996-2006 > Jun-2003 >

Replace Your File API’s With The FileDialog Object  

By Garry Robinson    (applies to Access 2002 and Access 2003)

Introduction – It is time to change your file picker  

For years now, the first thing I do after splitting a database into software and data databases is to add a module to my software database that has both a re-linking function and a file picker. This module originated from the free solutions database that came with Access 97.  Included in the module were many lines of visual basic that performed API calls to the Windows file dialog object.  I prefer to describe the API calls as ITHW calls (I hope that works).  Well it has worked well but I still cringe whenever I look at the code.  Thankfully in Access 2002 (XP), a FileDialog object has been included as part of the standard Microsoft Office object library.  This new object allows me to replace 350 lines of visual basic with 20 lines and as a bonus, it’s easier to understand.  Now my Access 2002 applications use this new object whenever I want the user to locate a file.

 

One of the best ways to make your database look like a “real application” is to tap into the standard Windows routines—

and using these routines also saves you time. Garry Robinson shows you how to use the Windows File Open

dialog to let your users select files the Windows way.

 

For years now, I’ve split my applications into two

databases: a software database (forms, reports,

queries) and one or more data databases (tables). As

a result, one of the first things that I add to my software

database is a module that has both a re-linking function

and a file picker. When the user opens the software

database, I check that the data database can be found and,

when it can’t, I open a window that lets users navigate to

the data database and select. Once they do, I re-link all the

tables in the data database to my software database.

This module has its origins in the free solutions

database that came with Access 97. Included in that

module were many lines of VBA code that performed API

calls to the Windows File dialog. I prefer to describe API

calls as IHTW calls (I Hope That Works). The routine has

worked well over the years, but I still cringe whenever I

look at the code.

 

Thankfully, in Access 2002 (XP), a FileDialog object

has been included as part of the standard Microsoft Office

object library. This new object allows me to replace 350

lines of code with 20 lines, and, as a bonus, the code is

easier to understand. The code is also easier to maintain,

the module loads faster because there’s less code, and my

application may even run a bit faster. All my Access 2002

applications use this new object whenever I want the user...

 

Read more in the pdf here: Accessing the FileDialog Object

 

 

200306_gr1  

Figure 1. The demonstration form for using the FileDialog object.

 

 

See Also

File Open Dialog Options