Solved

Access: need to auto link tables with settings from an INI file

Posted on 2011-02-27
4
489 Views
Last Modified: 2012-05-11
I have an Access database which successfully links tables upon startup. It retrieves the back end database location from an INI file. The trouble is that I am developing this application for a customer who has a different set up to mine.Within my VBA code I have hard-coded the location of that INI file. So, for example, I might keep the INI file on my C:\CustDb and this is hard-coded into my VBA code. It works fine on my setup, but if my customer has a different folder name to mine, my VBA code will not find the INI.

Is there a way of somehow having my VBA detect the location of the VBA file.
0
Comment
Question by:rick_danger
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:TinTombStone
ID: 34992763
Why not use the Registry to store the BE location and other DB prefs.  Does not need to be flash, GetSetting() and SaveSetting would do.  If, on first startup the registry entry is empty, then a default location could be checked. If thats no good then you can prompt the user for the location, and store it for next time.
0
 

Author Comment

by:rick_danger
ID: 35022197
TTS - sorry for the delay.

Is this considered a safe option? It worries me that I may be playing about with people's registry settings.

Is this easy to do? Do I need to use a tool for this?
0
 
LVL 6

Accepted Solution

by:
TinTombStone earned 500 total points
ID: 35025208
The GetSetting() and SaveSetting functions in VBA save settings to a particular part of the registry

HKEY_CURRENT_USER\Software\VB and VBA Program Settings

Which, as you can see is just for VB & VBA settings.  You use as follows

strINI = GetSetting("MyApp", "Settings", "INIFile", "C:\CustDb\MyINI.ini")

strBackColor = GetSetting("MyApp", "Settings", "BackColor", "")
strBackColor = GetSetting("MyApp", "Settings", "DisplyFormx", "")

SaveSetting "MyApp", "Settings", "INIFile", "C:\CustDb\MyINI.ini"

SaveSetting "MyApp", "Settings", "BackColor", "Blue"
SaveSetting "MyApp", "Settings", "DisplyFormx", "False"



Alternatively you could just install the ini file into the same folder as the database and use

strini = CurrentProject.Path & "\subfolder\myINI.ini"

By the way, how does the ini file know where the backend is?

That is also hard coded. presumably the location of the BE will be determined by you.  So rather than store the value in an ini file that may not be there, hard code the location of the backend.

Finaly, you could check for the existance of the "C:\CustDb" folder and create it if it is not present
0
 

Author Closing Comment

by:rick_danger
ID: 35025639
nice full answer - much appreciated.

Good name too!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now