Results 1 to 14 of 14
  1. #1
    Join Date
    Oct 2004
    Posts
    86

    Unanswered: Environment Variables

    Hi,

    How can i use environment variables in access ( i think thats what they are called)

    basically i want to say

    dest = "%userprofile%\desktop\" & "filename.mdb"

    which dosnt work but i have a file on each users desktop that i need to access from a generic database depending on the user

    does anyone know of a way of doing this?

    thank you

    Scott

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59

    ENVIRON Varaibles

    try the help system for ENVIRON
    usage is:
    strSetting=ENVIRON(<key>) or strSetting=ENVIRON(<index>)
    note the environment settings are machine / platform independant so the index is 'stuff all' use unless you want to view what environ settigns your platform supports. You cannot rely that the same <index> will retrieve the same info on each call even on the same machine

    I did a snapshot of 4..5 machines to find the environ settings we are comfortable with these are
    "TEMP" & / or "TMP" to fidn the location of the current PC's temp / scratch work area
    "NWUSERNAME" the Novell user logon
    "COMPUTERNAME" the PC NETBIOS NAME
    "USERNAME" the local PC account

    So to find the netware logon:- strSetting=Environ("nwusername")
    To find the current PC account:- strSetting=Environ("username")
    etc...

    But theres a lot more to it, you can find all manner of stuff, not sure what you'd use for though. This should give a pointer, come back if you need a few more assistance. I did a dump to a flat file iterating through using the key 1..255 to retrieve all the ENVIRON variables. This is detailed in an application note I wrote for a site detailing the <keys> discovered which were of possible use on XP machines
    HTH
    Last edited by healdem; 11-23-04 at 06:49. Reason: lousy spelling

  3. #3
    Join Date
    Oct 2004
    Posts
    86
    Basically ive got a form that updates a file on each of the users desktop, the file that calls this updating form is the FE itself that is to be overwritten, but the update form needs to know where to put the file and as each user will be doing this it will need to be generically coded so that each copy can download the file to the userprofile i.e c:\winnt\profiles\username\desktop\...

    thanks for your help ill try this

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    So in this case you would probably want
    strVal = environ(“USERNAME”)
    strLocalSetting= "c:\winnt\profiles\" & strval & "\desktop\..."

    note it would be 'smart' to put in some range checking to make sure the returned value is valid ie not null or something else....

  5. #5
    Join Date
    Oct 2004
    Posts
    86
    yes i think thats right, ill try it, here is a snipet of the code im working with


    ' Load variables with correct file name-path values.
    strDest = "c:\winnt\profiles\barrsz\Desktop\" & "AADClient.mdb"
    strBkup = "c:\winnt\profiles\barrsz\Desktop\" & "AADClient_bkup.mdb"


    If Dir(strBkup) <> "" Then Kill strBkup
    FileCopy strDest, strBkup
    If Dir(strDest) <> "" Then Kill strDest


    End Sub

    Private Sub Form_Timer()
    On Error Resume Next

    Dim strSource As String
    Dim strMsg As String
    Dim strOpenClient As String
    Const q As String = """"

    DoCmd.Hourglass True
    DoEvents

    Err.Clear

    strSource = "G:\data\aad\latestclient\" & "AADClient.mdb" I also want this to use UNC paths instead
    FileCopy strSource, strDest

    DoEvents

    strOpenClient = "MSAccess.exe " & q & strDest & q
    Shell strOpenClient, vbNormalFocus

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    UNC paths should be site specific so I'm hoping you can handle this yourself. Had a quick look at the internal application note and it even has the profile
    strSetting=Environ("USERPROFILE"
    matthew

  7. #7
    Join Date
    Oct 2004
    Posts
    86
    Thank you Matthew i appriciate your help on this, ill report my outcome

  8. #8
    Join Date
    Oct 2004
    Posts
    86
    Thanks

    however ive tried this and i cant get strVal to store the %USERPROFILE%

    ive attached for your viewing if you would be kind enough to see where im going wrong? and point me in the right direction

    thank you
    Attached Files Attached Files

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Sorry can't read that db, I get user doesn't have adequate security to read or change database
    have you checked what environ variables area available on your machine?
    is it terminology but i read environ as read only - you can't set anything.
    matthew

  10. #10
    Join Date
    Oct 2004
    Posts
    86
    I have it working i put \Desktop\

    this works Great, it works on some machines but some of the other machines are newer and i think they are missing some dll's it breaks on the Environ bit

    does anyone know what the missing dll is? or what the environ uses?

    thanks

  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    scott
    You do need to check the environment variable you want is on all the machines you want to use it on. It is platform (OS) specific. It works on XP, 2000, & NT, it works partially in 98, and not at all on 95 & 3,3.1.

    It is all referred to in the help file / and or microsoft site if you search for environ, or in the code window highlight environ & press F1

  12. #12
    Join Date
    Oct 2004
    Posts
    86
    All machines are cloned from an image by my IT dept.

    all use NT, access97 and all SET the enviroment variables
    however the machines that are having problems are new ones to the office, even tho the image is the same im sure there are files missing

  13. #13
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have a look at: http://msdn.microsoft.com/library/de.../D6/S5B21A.asp
    which is the office 97 exaplnantion of the environ function within VB. It sounds like you are trying to set an environment string.

    I read this, and have used elsewhere environ to retrieve what you want
    eg strPathtoDesktop=envrion("USERPROFILE") & "\DESKTOP"
    on this pc it sets strPathtoDesktop to "c:\documents and settings\za9ra29\desktop"

    I would expect problems with older machines but not newer PC's

    You do need to check it works on your machines before deployment
    Why would you want to set an environment varaiable. the whole point of them is that the already exist, are defined and valid. if you tinker with them you may screw not just your application but others running elsewhere/elsewhen.

  14. #14
    Join Date
    Oct 2004
    Posts
    86
    to be honest, i think its somthing to do with access as opposed to the machine im getting

    "Compile Error, Cant find project or library" and it highlights the word "Environ" in blue, ive checked the references and they are the same on both PC's


    any more thoughts?

Posting Permissions

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