Wrox Programmer Forums
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 3rd, 2004, 12:37 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
Default Path to database backend

In Access, if the user changes the location of the database backend file Access seems to "remember" and links to that path the next time it is opened.

How can I emulate this behaviour in VB please? That is, give the user the opportunity of changing the source file and then remembering the new location for the next time.

Clive Astley
Clive Astley
Old September 30th, 2004, 06:05 AM
Friend of Wrox
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma

Well its not true that ACCESS locates the database automatically. U have taken it wrong.

Ideally U should give the opertunity to change the location. There are two general ways.

1) U can use DSNs . DSN are database nutral and if user changes the location of database file, he can recreate the DSN with same name with current modified location and applictaion can work through the DSN. (Hoipe u can find how to create DSN in Win 2000, Win 9x).

2) U can give a small screen to capture the Path of DB,userID etc. and save these in System registry. When eer u load the application it should search for the path in registry and if found it get connected otherwise should display the form asking location of database file. I this way u can change the database file path.

See SaveSetting, GetSetting in VB MSDN

Hope things are clear now

B. Anant
Old January 11th, 2007, 07:21 PM
Registered User
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Actually, incorrect. Access caches the DSN name, so just changing the DSN will result in linking errors, which may require a manual relink. The database must be relinked to recognize the changes in the DSN. You can write a script to check the DSN name for errors, i.e. something like this:
function RefreshDBLinks(NewDBPath as string)
 Dim LnkTbl as TableDef
 Dim StrStart as Long
 Dim StrEnd as long
 Dim RepStr as string
 for each LnkTbl in currentdb.TableDefs
  if LnkTbl.connect <> "" then
   strStart = instr(1,lnktbl.connect,"DATABASE=", vbTextCompare)
   StrEnd = instr(strstart,lnktbl.connect,";")
   If StrEnd = 0 then StrEnd = len(lnktbl.connect)
   RepStr = mid(lnktbl.connect,strstart,strend-strstart)
  end if
You will need to make distinction between ODBC links and BackEnd links, so check the connect string for each of your tables to check for differences. If you are just refreshing ODBC links or DSN Links, you can remove the code to replace the link location, and just do a refresh. This should refresh the ODBC links, or bring up a screen prompting for a new odbc link. I take no liability in assuming my code is error proof, so debugging and code checking is left to you.

Old January 12th, 2007, 01:29 AM
Friend of Wrox
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts

All you need is a way for the user to browse to the location, and then to save the location of the mdb file the user has selected.

As far as browsing - the easiest way will probably be by using the Common Dialog control in file open mode.

As far as saving the location, there are two very common ways to do this. One is to store it in the registry, and the other is to store it in a configuration file that is stored in a location that your application can always get to. The typical locoation for a file like this is in the root directory of the application. These used to be called ini files (ini = initialization) - but you can work this just about any way you want.

The registry is often used for this purpose, but lately I have avoided that unless it is something that really needs to be in a "central" location. For example - if you need to access the value from several different apps.

The file solution is probably the easiest.

If you have no experience with file access, let us know and I (or someone else here) is sure to help.

Woody Z

Similar Threads
Thread Thread Starter Forum Replies Last Post
Path to database takwirira ASP.NET 2.0 Basics 2 April 4th, 2008 09:25 AM
using app.path in database path and filename kd8con VB Databases Basics 2 October 25th, 2006 11:45 AM
Access database/SQL Server backend Question vbJupiter Access VBA 1 October 6th, 2006 07:59 PM
Automate Backup of backend database medix_911 Access VBA 1 August 31st, 2006 08:16 AM
Database Path sampow Access 1 December 4th, 2003 07:37 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.