DatabaseLessons.com

'Serving the Microsoft® Access
Community since 1997'

News/Blog
Tables
Queries
Forms
Reports
Modules
Miscellaneous
Subscribe
Free Samples
Videos
Services
Links
About Us

 

 

Remember INI Files

Remember the use of "ini" files in early versions of Windows? I suppose they are still used by some apps.  [ed. note - I just searched my Win98 hard drive and found 129 ini files, so I guess they are still used!]

Here is one way of using an ini file with Access.

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.

I often create an Access database that I want to have open differently for me than for the users. I have used various methods for doing this. (i) have a separate small mdb with settings in it and distribute a different one to the users than to me, (ii) have Access look for the existence of a specific file in a specific folder, and (iii) use an ini file to store a setting.

I will leave solution (i) to you. For solution (ii) look up the DIR command in VBA. Here is the code I use to read the first line of an ini file.

Dim strSetting as string

'---  open file for input.
Open "name_of_file" For Input As #1
'---  read in first line of file
Input #1, strSetting
'--- close file
Close #1 ' Close file.

Further Suggestions

Make the name of the file a variable string that determines the name of the folder that the database is in, so you can move the database around without having to change the code.

Make the logic capable of reading more than one line from the file, and determining the name of the setting. Remember how ini files used to work, with headings in [] brackets?

(article continues after sponsor spot)



Happy Coding

 
Note: This web site dedicated to MS Access database users is an independent publication of Richard W. Killey and is not affiliated with, nor has it been authorized, sponsored, or otherwise approved by Microsoft® Corporation.
 

 

© 2006, 2007, 2008 Richard W. Killey. All Rights Reserved. - Privacy Policy