Solved

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

Posted on 2011-02-27
4
513 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA Access 2016 syntax 6 43
How to use DLookup with IsNull Function 4 26
split XML field into many fields from MS Access 21 24
Modify report 8 6
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

777 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