call shell function in ms access not going to currentproject path

Posted on 2014-07-17
Last Modified: 2014-07-19
this code is not changing directory to the current project path. my access database is in several directories and I need to reference the current path.

the following code works fine, but not the flexible to current directory

Call Shell("cmd.exe /k cd\priworkfile\temp\zfws-6-1-14-mastergtest &&", vbNormalFocus)

this code does not cd to the currentdirectory

Private Sub Command7_Click()

    Dim NewName As String
    Dim OldName As String
    OldName = CurrentProject.Path
    NewName = Right(OldName, Len(OldName) - 2)

    MsgBox (NewName)
    'Dim Shell As String
    Call Shell("cmd.exe /k cd (NewName)" & """""", vbNormalFocus)
End Sub

would appreciate the correct setting to change to the current directory.
Question by:JimMello
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    <<would appreciate the correct setting to change to the current directory. >>

     You don't do a CD in the Shell() command, but rather specify the full path directly, or a relative path (using ..)

     If you want to change directories specifically, then you need to script out a batch file with the CD command in it and whatever else, then call the batch file with Shell()

    LVL 24

    Expert Comment

    You have a typo in your command. Try this one:
    Call Shell("cmd.exe /k cd " & NewName & "", vbNormalFocus)

    Open in new window


    Author Comment

    this does not work, error message, "the system cannot find the path specified."
    LVL 24

    Accepted Solution

    If you have spaces in the path name you need to enclose it in quotes, like this
    Call Shell("cmd.exe /k cd """ & NewName & """", vbNormalFocus)

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
    Article by: Leon
    Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
    The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now