Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing VB's Default Directory

Status
Not open for further replies.

Dmonkyking

Technical User
Apr 1, 2004
27
US
Hey,
Stupid question, but I have some code that backs up my database tables to another database, but in order to do that I had to put in the path of the databases when copying the tables. Now, of course, if this database was to move I'd have to change all the path locations. If I just input the backup database I want to back up my tables to(i.e. backup\backup.mdb), VB assumes I am backing up the info to my default directory (c:\documents and settings\..\..). This is a minor nuisance, but I really wanted to make this database universal so it wasn't tied to any specific location, obviously. Any help anyone can give me or direct me to a pst that may address this would be great. Thanks.
 
Take a look at the ChDir instruction and/or the Application.CurrentProject.Path property.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks again PH for steering me in the right direction. I actually have it working. The only thing I'm trying to work out is if the Backup directory does't exist then create it. I have the mkdir command all set up, but I haven't found the correct way of using an If statement with it, i.e.

If "Backup" doesn't exist then MkDir "Backup"

I have my backup.mdb database check set up like this:

If Dir("Backup\Backup.mdb") <> "" Then Kill "Backup.mdb"

After that it creates the backup database. That works fine, but I haven't figured out how to use that same approach for a directory. Any thing you can help me with or a command you can steer me to would be great. Thanks.
 
Brute force method:
On Error Resume Next
MkDir "Backup"
On Error GoTo 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks a lot PH, might not be pretty, but works perfectly. One more question, is there a better way to kill the backup.mds file. Meaning, the code I have now only will copy the tables to that database if it exists, i.e.:

If Dir("Backup\Backup.mdb") <> "" Then Kill "Backup.mdb"

I know there has to be a way where it checks to see if the file exists and then kills it if it exists. Like:

If Backup.mdb exists then delete it

I've be scouring through the VB help, but haven't stumbled on anything as of yet. If you have any info for me that would be great. Thanks for all the help so far :)

 
Nevermind, I guess this method does work fine. Just tried it out by deleting the directory and it created the backup dir and the backup.mds. Tried it again and still worked fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top