Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 3rd, 2004, 12:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Norwich, Norfolk, United Kingdom.
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
Reply With Quote
  #2 (permalink)  
Old September 30th, 2004, 06:05 AM
Friend of Wrox
 
Join Date: Sep 2004
Location: New Delhi, Dekhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

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
Reply With Quote
  #3 (permalink)  
Old January 11th, 2007, 07:21 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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)
   replace(lnktbl.connect,repstr,NewDBPath)
   LnkTbl.RefreshLink
  end if
 next
---------
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.

Reply With Quote
  #4 (permalink)  
Old January 12th, 2007, 01:29 AM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
http://www.learntoprogramnow.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.