Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Code for Connecting to Folder/File to open a mxd document!

I tried to make the title as thorough as I could. I need some help with VBA code for my dialog box. I have written code to add items into the combo box when the form is initiated but I am having trouble understanding how to pass the user selection into the code of my create map command button after it is clicked. My code is displayed below:

Private Sub UserForm_Initialize()

'Add Items to the Drop down List

cboStations.AddItem ("Annual") cboStations.AddItem ("Urban")

cboDistrict.AddItem ("Abilene") cboDistrict.AddItem ("Amarillo") cboDistrict.AddItem ("Atlanta") cboDistrict.AddItem ("Austin") cboDistrict.AddItem ("Beaumont") cboDistrict.AddItem ("Brownwood")

End Sub

Private Sub cmdMap_Click()

Dim userSelect As String
userSelect = ComboBox(" ")
Call CreateMap(userSelect)

End Sub

Private Sub CreateMap()

Dim cboStations As String
Dim cboDistrict As String

Dim userValue As String
userValue = cboDistrict.Text

Dim mapDocument As IMapDocument
Set mapDocument = New mapDocument

If mapDocument.IsPresent("K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\District_Maps\2012\Abilene\Abilene_Base_Map.mxd") Then
mapDocument.Open ("K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\District_Maps\2012\Abilene\Abilene_Base_Map.mxd")
    MsgBox "District Does Not Exist"
End If
share|improve this question

marked as duplicate by underdark Jan 30 '13 at 7:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Please -- STOP asking the same question over and over. Go through the comments and answers on your previous questions and try to respond to the people that have attempted to help you already. – blah238 Jan 16 '13 at 2:21
-1 it is about 7th time that i see this question repeated! – vinayan Jan 16 '13 at 3:00
I told you two times that, you are calling mapDocument.Open method in a wrong way. It takes two parameters not one. – Emi Jan 16 '13 at 4:48

At some point you will need to test the value of userValue and use that to build the path to the map document you are trying to open. I am not well versed in vba, so unfortunately I can't give a highly detailed explanation of how to accomplish this. I can offer some direction:

This will likely require multiple If/Else statements, probably one for each county you want to have a unique map for.

I would declare a string that is the path and then set that value for each condition in the result of your If/Else statements that evaluate userValue. So, if the user has picked "Abilene" the code sets the path string equal to the path of that map. If the user picks "El Paso" then the code sets the path string equal to the path of that map, and so on and so forth.

If userValue = 'Abilene' Then
    path = "[Drive]\Folder\Folder\Abilene.mxd"
ElIf userValue = 'El Pase' Then
    path = "[Drive]\Folder\Folder\ElPaso.mxd"
*{Series of ElIfs that deal with your other Counties Goes Here}*

Then, once the path string is built you use the If statement you have, but instead of passing the function the whole string, you just pass it the one you built in the If/Else statements above:

If mapDocument.IsPresent(path) Then
    mapDocument.Open (path)
    MsgBox "District Does Not Exist"
End If

As I said, I do now know if that is the proper syntax for those functions, I'm just hoping that this can give you some direction.

share|improve this answer
please look…. mapDocument.Open method does not take one parameter. It takes two parameters – Emi Jan 16 '13 at 4:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.