Results 1 to 11 of 11

Thread: VBA defaultFile

  1. #1
    Join Date
    Mar 2005
    Posts
    55

    Question Unanswered: VBA defaultFile

    How do you reference the default save location on a user computer using VBA

    I need for databse to run a command that needs a file that is auto saved to the user default location. It obviously varies on each computer

  2. #2
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    The only two "default" folders that I know of that you could get in VBA code would be the folder that MSAccess.exe is in and the folder that the current database is in. Here is the code for each of these:
    Folder where MSAccess.exe is: SysCmd(acSysCmdAccessDir)
    and the folder the current database is in: CurrentDB.Name
    The problem with CurrentDB.Name is that you will need to strip off the name of the Database out of what is returned by CurrentDB.Name.

    HTH,

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    If you're running XP then the following might be of use
    Code:
    Dim DefaultPath As String
    
    DefaultPath = "C:\Documents and Settings\" & Session("Username") & "\My Documents\"
    George
    Home | Blog

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Have a look at what the ENVIRON command can provide.

    I'm pretty certain that it includes various file/path locations.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    The problem with CurrentDB.Name is that you will need to strip off the name of the Database out of what is returned by CurrentDB.Name
    An alternative for this particular path is

    CurrentProject.Path


    MTB

  6. #6
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Thanks MTB! I keep forgetting that one.

  7. #7
    Join Date
    Mar 2005
    Posts
    55
    Thanks a heap i used a combination fo both

    healdm and georgev

    Dim UserNameA As String
    Dim DefaultPath As String

    UserNameA = VBA.Environ$("Username")
    DefaultPath = "\\blah\blah\blah\" & UserNameA & "\My Documents\report.pdf"

  8. #8
    Join Date
    Mar 2005
    Posts
    55
    CurrenProject.Path is nto applicable in my instance as the default save location was set in Adobe not in Access. So i need to retrieve the windows default location and the Environ$ function worked perfectly

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by Databaseman
    Thanks a heap i used a combination fo both

    healdm and georgev

    Dim UserNameA As String
    Dim DefaultPath As String

    UserNameA = VBA.Environ$("Username")
    DefaultPath = "\\blah\blah\blah\" & UserNameA & "\My Documents\report.pdf"

    please avoid using the username from Environ.. it cannot be trusted, in fact virtually anything in Environ can't be trusted (its too easily faked, overwritten or otherwise compromised).

    but it is a good source for things like temp work file locations.

    personally Id be looking for the ALLUSERSPROFILE, APPDATA, HOMEPATH,TEMP, or TMP options

    you can ge the username... always a good idea if you are spawning files to associate the files with a userid from either the API calls of Dev Hsish... try googling "Ashish API Access", or PKStormy's contribution to this site, which I think is in the code bank. Persoanlly I use the API calls, but each to their own.
    Last edited by healdem; 07-13-07 at 04:42.
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    In this situation it works fine, surely?

    I wouldn't have suggested it if I thought it would cause more problems when implementing it for this specific problem.
    George
    Home | Blog

  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    not really.. if its suspect its suspect in my books

    if you want to use a username to identify a file, then pull it from the easily available API or PK Stormy's stuff. Its not as if alternative methods which are just about as easy to use as environ/username.

    if its just to make the filename unique then there are other ways.

    Id agree it may well be acceptable in these circumstances, but I feel any use of Environ Username parameter is suspect, and Id hate people to go down the route of using it elsewhere, and come a cropper, (as I nearly did a few years back). Probably I get oto defensive when I see username being derived in this manner.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •