You are on page 1of 7

ebenezer.odoi@gmail.

com 2009

Password Protect you ArcMap Documents

This tutorial aims at setting a custom password for your ArcMap project file. Users will be asked for a valid password ( for this tutorial set to lovejesus). On a user entering a valid password the ArcMap document will open, otherwise, an empty ArcMap instance will be opened instead.
INITIAL SET-UP In a chosen folder save two ArcMap Documents. Once document should have at least a layer loaded in it (or better still a copy of one of your actual projects !!), the other file should be an empty ArcMap document: File1: <name of your project file> . In this tutorial Ill use password protect _jesus File 2: <name of the empty project file>. In this tutorial Ill name it myEmptyDocument

1. Open File1

ebenezer.odoi@gmail.com 2009
2. Press [Alt +F11] (hold down the control key and tab the F11 key). This will send you straight to the Visual Basic Editor.

OR
Go through the Tools menu > Macros >Visual Basic Editor

Both methods will send you to the VB Editor where we shall do most of our tasks today.

ebenezer.odoi@gmail.com 2009
3. First navigate in the project window to the ThisDocument file under the ArcMap Objects folder.

The ThisDocument file

4. In the visual basic editor double-click on the ThisDocument file to open its code window

Code Window For The ThisDocument file

ebenezer.odoi@gmail.com 2009

5. Consider the top of the ThisDocument code window (as shown below)

Object List

Procedure List

Modify the items in the list as shown below.

This code will show up when the two Lists are as shown above

The code structure which shows up tells you what happens when the two lists are true. In this case when the MxDocument (that is this Object/file) is on OpenDocument (when the Object is opened) .

At this point we are in the position to code for the task.

ebenezer.odoi@gmail.com 2009

6. Type the codes in red between the two lines of codes generated when you changed the object and procedure lists (in step 5)

Private Function MxDocument_OpenDocument() As Boolean Dim strPassword As String strPassword = InputBox("Enter Password", "Authenticate your Clearance") If strPassword = "lovejesus" Then MsgBox "Welcome staff member", vbOKOnly, "Clearance Authenticated" Else MsgBox ThisDocument.Title & " needs a valid Authentication to open" & _ " you will now be redirected." Application.NewDocument False, "h:\ebengiswebsite\tutorials\myEmptyDocument.mxt" End If End Function 1

EXPLANATION OF CODES. 1 We first have to define a string (text) to hold the password keyed-in by the user Dim strPassword As String the system should provide the user with an inputbox to provide his valid password Enter password will be displayed on the input box Authenticate your clearance will be the Title of the input box whatever the user inputs will be assigned as strPassword strPassword = InputBox("Enter Password", "Authenticate your Clearance")

ebenezer.odoi@gmail.com 2009
the resultant of this code will produce the image below when the ArcMap project is opened

ArcMap will demand a response from the user before normal functionality will work. So the user is forced to respond.

2 we use the If Statement to decide the system response for each instance. Each instant being determined by whether a valid password has been entered or not. first we find if the strPassword was assigned lovejesus If strPassword = "lovejesus" Then if that is true then the system moves to execute the next line of code MsgBox "Welcome staff member", vbOKOnly, "Clearance Authenticated" which produces a message box Welcome staff member with Title Clearance Authenticated Also only the ok button is displayed vbOkOnly

ebenezer.odoi@gmail.com 2009
then to activate the condition of strPassword not being lovejesus we use Else Else the code after Else tells the system what it should do when the initial condition set by the If is not satisfied first a message box should be displayed everything after the call of the message box will return a string in this case MsgBox ThisDocument.Title & " needs a valid Authentication to open" & _ " you will now be redirected." ThisDocument.Title will return the project name as a string & is used to join two strings By now its evident that all strings should be typed within quotation marks _ allows us to break a long lines of code into two separate lines ..its helps avoid endless horizontal scrolling . *(there should always be a space before the underscore )

after we display the message box we want the application to open the empty map (File 2) Application.NewDocument False, "h:\ebengiswebsite\tutorials\myEmptyDocument.mxt" the nice thing about the above code is that if it doesnt find your file path (h:\XXXXXX) it will still open a blank document (after a informing you that it couldnt locate the file you specified). Great !!!

now after all has been said and done so we need to end the If condition statement End If

Protecting who has access to project files is very important to GIS firms. In later parts of the tutorials well learn how to link a database to a password form, which will allow different levels of project file modification privileges. Until then Stay Blessed.!!!!!!

You might also like