?
Solved

Getting the current working directory

Posted on 2003-03-11
6
Medium Priority
?
381 Views
Last Modified: 2010-04-07
Is there a system command in VB to retrieve the current working directory?

I want open a word file using VBA and I'd like to have the CWD as a point of reference than hard coding a full path.

I apologize for the simplicity of this question but I'm trying to move into VB from VC++.

Thanks,

Ray
0
Comment
Question by:bjs19
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8116025
have you tried app.path ?
0
 

Author Comment

by:bjs19
ID: 8116177
I tried app.path but it only give me where word.exe is located. I'd like to grab where the database file is kept.? How could I grab the location of the access db?
0
 
LVL 1

Accepted Solution

by:
SilentRage earned 200 total points
ID: 8116223
Retrieve the current directory VB's way

PathWithNoEndingBackslash = CurDir()

Retrieve the current directory API way

Private Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectoryA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Sub Form_Load()
Dim Buffer As String * 255
Dim Length As Long, CWD As String

    Length = GetCurrentDirectory(255, Buffer)
    CWD = Left(Buffer, Length)
    Debug.Print CWD
End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:SilentRage
ID: 8116231
oh, here's some related VB functions:

Change current directory
ChDir "C:\windows"

Change current drive
ChDrive "C:\"
0
 
LVL 27

Expert Comment

by:Dabas
ID: 8116233
You can use the CurDir function to find the current directory.

This is a paste from VBA help

----------Paste starts here---------
Returns a Variant (String) representing the current path.

Syntax

CurDir[(drive)]

The optional drive argument is a string expression that specifies an existing drive. If no drive is specified or if drive is a zero-length string (""), CurDir returns the path for the current drive
----------End of paste------------

Alternatively, you can use the file system object:

In References check Microsoft Scripting Runtimes.

Then use the GetAbsolutePathName function to get the exact location of the database file.

If I did not understand you correctly, you can also press F2 and browse the other Get.. functions exposed by the Scripting library, maybe you will find the most appropriate one to solve your problem

Dabas
0
 

Author Comment

by:bjs19
ID: 8119575
That is exactly what I was looking for. Short and sweet. I'm able to set and grab the file paths as I want now. That so much

Ray
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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