How to get Acc2003 to default to current directory?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    How to get Acc2003 to default to current directory?

    Hi all.

    Is there any way to tell Access 2003 (and/or 2000) to default to the current directory where I started it? Every time I open a database and go to do an Import or whatever, the damned thing starts in My Documents.

    I don't think the "default database folder" option is likely to be any use, unless there's some way to set it dynamically to point to the current (or "working") folder.

    Not crucial, of course, just very annoying.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Killer42
    Hi all.

    Is there any way to tell Access 2003 (and/or 2000) to default to the current directory where I started it? Every time I open a database and go to do an Import or whatever, the damned thing starts in My Documents.

    I don't think the "default database folder" option is likely to be any use, unless there's some way to set it dynamically to point to the current (or "working") folder.

    Not crucial, of course, just very annoying.
    'This little Code snippet will automatically change the Current Directory to the
    'Directory where Msaccess.exe is located. I know it's not exactly what you
    'wanted, but it may point you in the right direction. Hope it helps..

    Dim varRet
    Code:
    varRet = SysCmd(acSysCmdAccessDir)
    Code:
    ChDir varRet

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by ADezii
      'This little Code snippet will automatically change the Current Directory to the 'Directory where Msaccess.exe is located. I know it's not exactly what you 'wanted, but it may point you in the right direction. Hope it helps..
      Dim varRet
      Code:
      varRet = SysCmd(acSysCmdAccessDir)
      Code:
      ChDir varRet
      Thanks ADezii.

      You're right, it's not exactly what I was after, but is certainly a helpful idea. I could run something similar from an Autoexec macro, at the least. I'll give it a shot and let you know how it goes.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Well, it's not particularly elegant, but it works.

        I placed RunCode FixTheStupidDef ault ( ) in my AutoExec macro, and in that Function, just did ChDir to a hard-coded path. Works like a charm. What I need to do now, of course, is to decide how I'm going to choose what path to put in there. Admittedly most of my Access work is in the same path, but not all.

        Hm... I might try investigating things such as the FullPath property - if I get the path+name for the current database, I can extract the path and use that. I'm better in VB, not that familiar with the object model in Access. But I'll get it...

        Comment

        • hashem417
          New Member
          • Jan 2015
          • 1

          #5
          Code:
          DefaultWorkingDirectory = Application.GetOption("Default Database Directory")
          
          Application.SetOption "Default Database Directory", getFilePath(strFullName)
          
          Function getFilePath(ByVal fullFileName As String) As String
             Dim sFileName As String, RevPath As String
             sFileName = StrRev(fullFileName)
             RevPath = Mid(sFileName, InStr(1, sFileName, "\"))
             getFilePath = StrRev(RevPath)
          End Function
          
          Function StrRev(ByVal sData As String) As String
             Dim i As Integer
             Dim sOut As String
             sOut = ""
             For i = 1 To Len(sData)
                sOut = Mid(sData, i, 1) & sOut
             Next i
             StrRev = sOut
          End Function
          default database directory stored in windows registery in this key:
          HKEY_CURRENT_US ER\Software\Mic rosoft\Office\1 4.0\Access\Sett ings
          Default Database Directory --> REG_SZ --> E:\Database\Acc ess\
          Last edited by Rabbit; Jan 15 '15, 09:33 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

          Comment

          • anvidc
            New Member
            • Sep 2007
            • 28

            #6
            You may try this
            Code:
            Application.CurrentProject.Path

            Comment

            Working...