44. VBA - Environ (Programming In Access 2013)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello again everyone and welcome back to programming in Access 2013 my name is Steve Bishop today we're going to be continuing our series again on VBA or Visual Basic for applications today we're going to be covering a very fun little fun little function that is available to us that can grab environment information about the computer that accesses running on and now it'd be the environ so let's take a look at it here I've got a once again on my form that's going to be loading I've got some functions that are going to run here some some VBA code that's going to run so let's go ahead and go through this here all right the first thing is notice that we've got the use of the word environ and then in parentheses we're passing along a argument that is a string argument and in this particular case I'm passing along the string argument of username what that does is we'll see down here at the bottom it sure enough it passes in the username that I am currently logged into the computer with you see this this is the name that I'm currently logged into the computer with and that's why when I look at the environment environ for a username I get the return of Steve that's pretty helpful we could also use the one very common thing is you'll see this dollar sign put after the environ function and that's a performance issue it just kind of gives us a little performance boost and you can see that the computer name that I am currently on is Steve's - PC so that's one very handy way to handle certain things for example I actually built a script that goes through and depending upon who is logged into which computer will set the printer for specific reports because some people have label printers and some people don't in so certain reports need to print to those label printers and that's a way that you can go and find out who is logged in to which computer so let's look through some some of these other different environs that you can go take a look at and I don't know them all off the top of my head those are the two primary ones that I use the most but there are others that are available to us so let's go ahead and take a look all right let me delete all these let it go and let's take a look all users profile so if we typed in something like environ oops envy run there you go I said all users profile that would then return currently the program data as the return results you can see how this is laid out here on our immediate window this would be what the value is that we would need to pass in as our string and this is what currently would be the value that we would get as a return at least for my particular computer computer this is the environment that we're running in now all right so app data is currently pointing to this directory common Program Files common Program Files for 32-bit and then here's a common Program Files for 64-bit and here's that computer name there's comm spec which is just basically you know where your command prompt is located at you can see it's located there see windows system32 dot cmd.exe and there you go that's where that currently is located home drive home path so this is where the path to the current username this is the path to their home and this is this could change based upon active order active directory if you were on a domain if you're you know if you work in a business office and your computer network is set up with a central computer that runs Active Directory so that everybody is on a domain then this home path might change based upon certain users there's also the local AppData logon server and this would be that location of what it where the active directory is currently being housed and since I am not currently on a domain my local computer actually acts as the logon server okay but if you were on a domain this would actually be pointing to that computer that is holding your Active Directory little plugin path Windows Defender and see what else we got in here does the operating system number of processors these are default paths that are built into into Windows I don't know if you know are too familiar with this but you can go to the property here and if I look under the advanced system settings here under see if I can find it here got to remember where is I forgotten myself sometimes there we go environment variables there we go there is the temp temp there's that Mo's plug-in path that we saw before and here are some of the system variables so there's comm spec FP host number of processors OS path path text there's the processor architecture processor identifier these are all different system variables that are going to be accessible to us using that environment alright so that's a path right here is one of them and this is again just pointing to basically these are paths that are going to be housed that when we type something in here in our command prompt for an executable so like ms access exe it's first going to look through all of these paths in this path variable to see if we can find that ms access exe file and then go ahead and execute it and I'm kind of digging around in the weeds here but I just thought you should know what that's all about path text architecture there's that amd64 again these are all those environment variables there are paths program data program files so here's where the normal program files are but if on it x86 32-bit and then they're going to be in Program Files so if it's a if it's an application that is the 32-bit application running on your 64-bit machine it's going to be stored under the Program Files directory here's for the 64-bit version of Program Files there's the public folder so everything that basically all of the folders and all the files that are under this particular file are shared on the network so long as I have that public folder being available on the network just kind of the default of where files can be seen on my computer session name system drive system route temp temp there's the user domain ok and the user domain ik is again it's that it's the domain that you would be logged into so if your office company let's say you worked for a company called nougat ok and nu GE T well nougat com might be the domain name of your of your network that all of your computers are linked into and so you may be able to retrieve what the user domain is and that would be nougat comm but since again since I'm just using my local machine and I'm not part of any domain it's only going to return my local computer name there's that user name that's where the user profile is stored which is really helpful if I want to start trying to save files specifically to the Documents folder of the user that may be logged in to maybe I want my application to save files specifically based upon the user profile well here's where I can go in and grab that user profile variable and then just put a backslash after the after this and say documents or my documents and or if I want to just specially make my own folder there then we have wind directory and etc etc again if you want to this is code that I actually pulled from off of the stack overflow by this very helpful post by rang so you're welcome to go ahead and look it up just I I just want an environment code sample for VB and lo and behold I came up with this little code snippet here that goes through and lists all of the environment variables that are available to me so if you're looking for one in particular that's a good way to find it
Info
Channel: Programming Made EZ
Views: 33,806
Rating: 4.9759035 out of 5
Keywords: Microsoft, Access, 2013, Programming, VBA, Visual Basic, Applications, tutorial, lesson, guide, database, SQL, beginner, advanced, software, microsoft access, table, query, form, code, coding, development, visual basic for applications, computer programming, environment variables, environ, username, computername
Id: nQ_x0UNJmXA
Channel Id: undefined
Length: 9min 6sec (546 seconds)
Published: Sun Mar 09 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.