Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-27
4
Medium Priority
?
560 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

879 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