Solved

Button OnClick and combo box

Posted on 2012-03-22
7
296 Views
Last Modified: 2012-04-16
I am creating a new tab in word 2010 for custom templates
My xml file is working great and adds 5 buttons on the tab inserted after the info tab. Beside each button I have a combo box that has 9 items
can anyone tell me how I can make my button onAction event open a
OpenFileDialog() based on the cbo selection??
Here is the code I am trying

Sub OnAction(ByVal control As IRibbonControl)
Dim myStream As Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()

If "cbo01" = "item01" Then
openFileDialog1.InitialDirectory = \\xxxxxxxxxxx
ElseIf "cbo1" = "item02" Then
openFileDialog1.InitialDirectory = \\xxxxxxxx
ElseIf "cbo1" = "item03" Then
openFileDialog1.InitialDirectory = \\xxxxxx
ElseIf "cbo1" = "item04" Then
openFileDialog1.InitialDirectory = \\xxxxxxx
ElseIf "cbo1" = "item05" Then
openFileDialog1.InitialDirectory = \\xxxxxxxxx
ElseIf "cbo1" = "item06" Then
openFileDialog1.InitialDirectory = \\xxxxxxxxx
ElseIf "cbo1" = "item07" Then
openFileDialog1.InitialDirectory = \\xxxxxxxxx
ElseIf "cbo1" = "item08" Then
openFileDialog1.InitialDirectory = \\xxxxxxxx
ElseIf "cbo1" = "item09" Then
openFileDialog1.InitialDirectory = \\xxxxxxxx

End If
openFileDialog1.ShowDialog()
End Sub


TIA
0
Comment
Question by:smithandandersen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Expert Comment

by:gman84
ID: 37751841
Firstly your better off using a CASE statement instead of an IF statment for this. But to get the value of a combo box you just use it's id and the TEXT property:
e.g.
cbo1.text

Select Case cbo1.text
    Case "item01"
        openFileDialog1.InitialDirectory = \\xxxxxxxxxxx
    Case "item02"
        openFileDialog1.InitialDirectory = \\xxxxxxxx
....
End Select

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37765214
Is the text displayed in combobox not path of directory? If it is, you can use that as initialdirectory value

openfiledialog1.initialdirectory = cbo1.text

if its not, you can set the text and value of the combobox when populating and then

openfiledialog.initialdirectory = cbo1.selectedvalue
0
 
LVL 6

Author Comment

by:smithandandersen
ID: 37767181
Hi Codecruiser

The text displayed in the combobox is drawn from the xml file

<comboBox id="cbo01" label="Template Type" >
                <item id="item01" label="01-Proposal"/>
                <item id="item02" label="02-Project Admin"/>
                <item id="item03" label="03-Permit Docs"/>
                <item id="item04" label="04-Construction Admin"/>
                <item id="item05" label="05-Inter-Office"/>
                <item id="item06" label="06-Prime Consultant"/>
                <item id="item07" label="07-CheckLists"/>
                <item id="item08" label="08-FootPrint"/>
                <item id="item09" label="09-Test-Dont Use"/>
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37769152
Where do you get the actual path?
0
 
LVL 6

Author Comment

by:smithandandersen
ID: 37770677
This is the code I have been trying

Sub OnAction(ByVal control As IRibbonControl)
        Dim myStream As Stream = Nothing
        Dim openFileDialog1 As New OpenFileDialog()

        If "cbo01" = "item01" Then
            openFileDialog1.InitialDirectory = "\\torvsrvfile\officetemplates$\TorontoOfficeTemplates\01-Proposal"
        ElseIf "cbo1" = "item02" Then
            openFileDialog1.InitialDirectory = "\\torvsrvfile\officetemplates$\TorontoOfficeTemplates\02-Project admin"
        ElseIf "cbo1" = "item03" Then
            openFileDialog1.InitialDirectory = "\\torvsrvfile\officetemplates$\TorontoOfficeTemplates\03-Permit Documents"
        ElseIf "cbo1" = "item04" Then
            openFileDialog1.InitialDirectory = "\\torvsrvfile\officetemplates$\TorontoOfficeTemplates\04-Construction Admin"
        ElseIf "cbo1" = "item05" Then
            openFileDialog1.InitialDirectory = "\\torvsrvfile\officetemplates$\TorontoOfficeTemplates\05-Inter-Office"
0
 
LVL 5

Accepted Solution

by:
gman84 earned 500 total points
ID: 37770682
openFileDialog1.InitialDirectory = ""\\torvsrvfile\officetemplates$\TorontoOfficeTemplates\" & cb01.text

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37772307
gman84 got onto it before I could.

It appears that the text in your combobox is actually the foldername that you are trying to set. If this is always the case then you can use the code suggested above to simplify it.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question