Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Shell to app in the same folder

Discussion in 'Information Technology' started by Bob Richardson, Nov 18, 2005.

  1. Bob Richardson

    Bob Richardson
    Expand Collapse
    Guest

    When a user clicks a button on my form, I want to Shell to MyApp, which is
    in the same folder as my MDB.

    It works if I include the entire path; e.g.

    stAppName = "C:\Documents and Settings\Bob\My Documents\BW\MyApp.exe"
    Call Shell(stAppName, 3)

    but this is cumbersome, since I want to be able to move my MDB (and of
    course MyApp.exe) to other folders on other computers.

    Since my MDB is in the C:\Documents and Settings\Bob\My Documents\BW\
    folder, I would have thought that the CurDir would be that. However, when I
    run

    MsbBox CurDir

    it shows "C:\Documents and Settings\Bob\My Documents\"

    in otherwords, it doesn't show the "BW" at the end.

    I'd like to Shell to an app in the same folder by just using:

    Call Shell("MyApp",3)

    Anyone know what's going on, and why the current directory is not where my
    MDB is? How would I change the directory back to the same directory as my
    MDB?
     
  2. Loading...


  3. Van T. Dinh

    Van T. Dinh
    Expand Collapse
    Guest

    If you use A2000 or later:

    CurrentProject.Path

    will give you the dir. the MDB (Front-End in a split system) resides.

    --
    HTH
    Van T. Dinh
    MVP (Access)



    "Bob Richardson" <bobr at whidbey dot com> wrote in message
    news:reidnaeBCLGKvuDeRVn-pQ@whidbeytel.com...
    > When a user clicks a button on my form, I want to Shell to MyApp, which is
    > in the same folder as my MDB.
    >
    > It works if I include the entire path; e.g.
    >
    > stAppName = "C:\Documents and Settings\Bob\My Documents\BW\MyApp.exe"
    > Call Shell(stAppName, 3)
    >
    > but this is cumbersome, since I want to be able to move my MDB (and of
    > course MyApp.exe) to other folders on other computers.
    >
    > Since my MDB is in the C:\Documents and Settings\Bob\My Documents\BW\
    > folder, I would have thought that the CurDir would be that. However, when
    > I run
    >
    > MsbBox CurDir
    >
    > it shows "C:\Documents and Settings\Bob\My Documents\"
    >
    > in otherwords, it doesn't show the "BW" at the end.
    >
    > I'd like to Shell to an app in the same folder by just using:
    >
    > Call Shell("MyApp",3)
    >
    > Anyone know what's going on, and why the current directory is not where my
    > MDB is? How would I change the directory back to the same directory as my
    > MDB?
    >
     
  4. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    And if you're still using Access 97 or earlier, you can use

    Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))

    Note that this includes the terminating slash, while CurrentProject.Path
    doesn't.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)



    "Van T. Dinh" <VanThien.Dinh@discussions.microsoft.com> wrote in message
    news:eKEKws96FHA.744@TK2MSFTNGP10.phx.gbl...
    > If you use A2000 or later:
    >
    > CurrentProject.Path
    >
    > will give you the dir. the MDB (Front-End in a split system) resides.
    >
    > --
    > HTH
    > Van T. Dinh
    > MVP (Access)
    >
    >
    >
    > "Bob Richardson" <bobr at whidbey dot com> wrote in message
    > news:reidnaeBCLGKvuDeRVn-pQ@whidbeytel.com...
    >> When a user clicks a button on my form, I want to Shell to MyApp, which
    >> is in the same folder as my MDB.
    >>
    >> It works if I include the entire path; e.g.
    >>
    >> stAppName = "C:\Documents and Settings\Bob\My Documents\BW\MyApp.exe"
    >> Call Shell(stAppName, 3)
    >>
    >> but this is cumbersome, since I want to be able to move my MDB (and of
    >> course MyApp.exe) to other folders on other computers.
    >>
    >> Since my MDB is in the C:\Documents and Settings\Bob\My Documents\BW\
    >> folder, I would have thought that the CurDir would be that. However, when
    >> I run
    >>
    >> MsbBox CurDir
    >>
    >> it shows "C:\Documents and Settings\Bob\My Documents\"
    >>
    >> in otherwords, it doesn't show the "BW" at the end.
    >>
    >> I'd like to Shell to an app in the same folder by just using:
    >>
    >> Call Shell("MyApp",3)
    >>
    >> Anyone know what's going on, and why the current directory is not where
    >> my MDB is? How would I change the directory back to the same directory
    >> as my MDB?
    >>

    >
    >
     
  5. Bob Richardson

    Bob Richardson
    Expand Collapse
    Guest

    I have Office 2003.

    The directory shown in CurDIr of CurrenteProject.Path DEPENDS on how you
    opened your MDB. If you click on the MDB file you get one result, if you
    open the mdb file from Access, you get another!!!! This has to be the most
    obtuse bug I've encountered.

    If you use Application.CurrentProject.Path, it works consistently. This has
    worked.

    ChDir Application.CurrentProject.Path
    stAppName = "AssignClasses.exe"
    Call Shell(stAppName, 3)

    You can't use ChDir CurrentProject.Path because you'll gewt a different
    result, depending on how your MDB was opened. Go figure.

    "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    news:%23yxotsD7FHA.1020@TK2MSFTNGP15.phx.gbl...
    > And if you're still using Access 97 or earlier, you can use
    >
    > Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))
    >
    > Note that this includes the terminating slash, while CurrentProject.Path
    > doesn't.
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
    >
    > "Van T. Dinh" <VanThien.Dinh@discussions.microsoft.com> wrote in message
    > news:eKEKws96FHA.744@TK2MSFTNGP10.phx.gbl...
    >> If you use A2000 or later:
    >>
    >> CurrentProject.Path
    >>
    >> will give you the dir. the MDB (Front-End in a split system) resides.
    >>
    >> --
    >> HTH
    >> Van T. Dinh
    >> MVP (Access)
    >>
    >>
    >>
    >> "Bob Richardson" <bobr at whidbey dot com> wrote in message
    >> news:reidnaeBCLGKvuDeRVn-pQ@whidbeytel.com...
    >>> When a user clicks a button on my form, I want to Shell to MyApp, which
    >>> is in the same folder as my MDB.
    >>>
    >>> It works if I include the entire path; e.g.
    >>>
    >>> stAppName = "C:\Documents and Settings\Bob\My Documents\BW\MyApp.exe"
    >>> Call Shell(stAppName, 3)
    >>>
    >>> but this is cumbersome, since I want to be able to move my MDB (and of
    >>> course MyApp.exe) to other folders on other computers.
    >>>
    >>> Since my MDB is in the C:\Documents and Settings\Bob\My Documents\BW\
    >>> folder, I would have thought that the CurDir would be that. However,
    >>> when I run
    >>>
    >>> MsbBox CurDir
    >>>
    >>> it shows "C:\Documents and Settings\Bob\My Documents\"
    >>>
    >>> in otherwords, it doesn't show the "BW" at the end.
    >>>
    >>> I'd like to Shell to an app in the same folder by just using:
    >>>
    >>> Call Shell("MyApp",3)
    >>>
    >>> Anyone know what's going on, and why the current directory is not where
    >>> my MDB is? How would I change the directory back to the same directory
    >>> as my MDB?
    >>>

    >>
    >>

    >
    >
     
  6. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    It's not a bug. It's a case of you not realizing that CurDir wasn't designed
    to return the directory that the application is in: it's supposed to return
    the Current Directory.

    When you create a shortcut, you have the option of specifying a Start In
    folder. If you open Access using that shortcut, the Current Directory will
    be the Start In folder. (This is true whether the shortcut simplies open
    Access, or opens a particular file in Access)

    If you open Access then select File | Open, the current directory gets
    changed to wherever you navigated in the File Open dialog.

    If you open Access and select one of the databases from the MRU (Most
    Recently Used) list, or if you open a database by clicking on the MDB name
    in Windows Explorer, the current directory gets changed to whatever you've
    set the Default Database Folder to on the General tab under Tools | Options.

    You also have the ability to change the value of CurDir using the ChDir
    and/or ChDrive statements.

    Your comment about ChDir CurrentProject.Path not always working implies that
    CurrentProject.Path points to a different drive than CurDir: the ChDir
    function only changes directory, not drive. See whether the following works
    any more consistently for you:

    ChDrive CurrentProject.Path
    ChDir CurrentProject.Path

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)



    "Bob Richardson" <bobr at whidbey dot com> wrote in message
    news:V8ednZ_I6OII8uPenZ2dnUVZ_t2dnZ2d@whidbeytel.com...
    >I have Office 2003.
    >
    > The directory shown in CurDIr of CurrenteProject.Path DEPENDS on how you
    > opened your MDB. If you click on the MDB file you get one result, if you
    > open the mdb file from Access, you get another!!!! This has to be the most
    > obtuse bug I've encountered.
    >
    > If you use Application.CurrentProject.Path, it works consistently. This
    > has worked.
    >
    > ChDir Application.CurrentProject.Path
    > stAppName = "AssignClasses.exe"
    > Call Shell(stAppName, 3)
    >
    > You can't use ChDir CurrentProject.Path because you'll gewt a different
    > result, depending on how your MDB was opened. Go figure.
    >
    > "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    > news:%23yxotsD7FHA.1020@TK2MSFTNGP15.phx.gbl...
    >> And if you're still using Access 97 or earlier, you can use
    >>
    >> Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))
    >>
    >> Note that this includes the terminating slash, while CurrentProject.Path
    >> doesn't.
    >>
    >> --
    >> Doug Steele, Microsoft Access MVP
    >> http://I.Am/DougSteele
    >> (no e-mails, please!)
    >>
    >>
    >>
    >> "Van T. Dinh" <VanThien.Dinh@discussions.microsoft.com> wrote in message
    >> news:eKEKws96FHA.744@TK2MSFTNGP10.phx.gbl...
    >>> If you use A2000 or later:
    >>>
    >>> CurrentProject.Path
    >>>
    >>> will give you the dir. the MDB (Front-End in a split system) resides.
    >>>
    >>> --
    >>> HTH
    >>> Van T. Dinh
    >>> MVP (Access)
    >>>
    >>>
    >>>
    >>> "Bob Richardson" <bobr at whidbey dot com> wrote in message
    >>> news:reidnaeBCLGKvuDeRVn-pQ@whidbeytel.com...
    >>>> When a user clicks a button on my form, I want to Shell to MyApp, which
    >>>> is in the same folder as my MDB.
    >>>>
    >>>> It works if I include the entire path; e.g.
    >>>>
    >>>> stAppName = "C:\Documents and Settings\Bob\My Documents\BW\MyApp.exe"
    >>>> Call Shell(stAppName, 3)
    >>>>
    >>>> but this is cumbersome, since I want to be able to move my MDB (and of
    >>>> course MyApp.exe) to other folders on other computers.
    >>>>
    >>>> Since my MDB is in the C:\Documents and Settings\Bob\My Documents\BW\
    >>>> folder, I would have thought that the CurDir would be that. However,
    >>>> when I run
    >>>>
    >>>> MsbBox CurDir
    >>>>
    >>>> it shows "C:\Documents and Settings\Bob\My Documents\"
    >>>>
    >>>> in otherwords, it doesn't show the "BW" at the end.
    >>>>
    >>>> I'd like to Shell to an app in the same folder by just using:
    >>>>
    >>>> Call Shell("MyApp",3)
    >>>>
    >>>> Anyone know what's going on, and why the current directory is not where
    >>>> my MDB is? How would I change the directory back to the same directory
    >>>> as my MDB?
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     

Share This Page