Solved

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

Posted on 2011-02-27
4
542 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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