?
Solved

Getting the current working directory

Posted on 2003-03-11
6
Medium Priority
?
417 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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 Month8 days, 3 hours left to enroll

615 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