p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB Databases Basics (http://p2p.wrox.com/forumdisplay.php?f=82)
-   -   using app.path in database path and filename (http://p2p.wrox.com/showthread.php?t=49408)

kd8con October 25th, 2006 12:51 AM

using app.path in database path and filename
I'm creating an application on my E drive. This application uses an access database. In the property list for the data control when I browse for the database location is assigns it as e:/shopkeeper/shopkeeper.mdb. This isn't a problem while debuging and developing. But when creating the setup package using the package wizard is where the problem comes in.

Installing this on another computer goes great. But when starting the application, it crashes and says it cannot find e:\shopkeeper\shopkeeper.mdb. How the heck can I fix this problem. I tried manually entering the database into the properties window like app.path & "\shopkeeper.mdb" and then it doens't work from the IDE.

Need some assistance on this one. couldn't find anything on mdsn or the internet for this.

I have one other problem, which might be easier to solve, so I'll save it for later.

Thanks guys - in advanced.


gbianchi October 25th, 2006 09:08 AM

hi there..

you will have to provide the path to the datacontrol by code and then make the connection.



woodyz October 25th, 2006 11:45 AM

You have several choices in how you can go about this.

The essential task is to dynamically set the DatabaseName property of the datacontrol in code.
Here is what it looks like "hard-coded" to a specific path, which isn't what you want:

Data1.DatabaseName = "e:\shopkeeper\shopkeeper.mdb"

What you need to do is either install the database in some path that you know ahead of time and can hard code into your app, or allow the user to set the path either during the setup process or directly from your application. When a path is entered by the you can store that path in the registry, or in a configuration or ini file of some type that your application is aware of and knows how to access to get the path.

So... lets say you write a function called GetDbPath which returns the path entered by the user. The your code would look something like this:

Data1.DatabaseName = GetDbPath & "\shopkeeper.mdb"

The call to refresh is needed when you are setting properties in code, as this refetches the recrodset.

Woody Z http://www.learntoprogramnow.com

All times are GMT -4. The time now is 05:44 AM.

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