Retrieve infopath field value

Hi,

I'm trying to get the value of a form field to use in an If Statement on an infopath 2007 form. I'm used to VBA where I could use "If me.fieldname.value = X then..." however I'm struggling to find the equivalent in VB.

Thanks,
Duncan
Public Sub CTRL225_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
           If  "code to go here" Then

            Application.XmlForms.Open("http://sharepoint.xxxxxxx.net/Sites1/SPptmvpt/TRS3/Country%20Risk%20Assessment/Pakistan.xml", XmlFormOpenMode.ReadOnly)
            Else
                Application.XmlForms.Open("http://sharepoint.xxxxxxx.net/Sites1/SPptmvpt/TRS3/Country%20Risk%20Assessment/Angola.xml", XmlFormOpenMode.ReadOnly)
            End If
        End Sub

Open in new window

dgoldieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Clay FoxDirector of Business IntegrationCommented:
in InfoPath you can add a condition or use a field value in a rule or function.

In code you must use the xDocument reference and usually the .text gets the actual value.
www.infopathdev.com has sample code.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgoldieAuthor Commented:
Struggling a bit with the code, I'll have to start again in the morning.

The reason I nead to use code is because from rules I can only open a new form as opposed to an existing form and I need to use an if statement to choose which form to open so as far as I can see there is no alternative.
0
Clay FoxDirector of Business IntegrationCommented:
OK, but you could use InfoPath logic to determine the form needed, then in your code just reference a field value for the ID or whatever and concatenate it into the path to the form.

If you are using SharePoint, you can connect to the form library and use logic to build a dynamic Hyperlink control to the form you need, which accomplishes the same thing.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

dgoldieAuthor Commented:
Thanks, it's nearly end of day here so I'll look again tomorrow and let you know how I fare.
0
dgoldieAuthor Commented:
I managed to find the solution; below is the code which does the job (although not the final version).

The reason I can’t use a hyperlink is because the form I need to open is based on a different dataset and needs to be filtered - the button allows me to set the filter at the same time I open the form whereas with a hyperlink I would need to set the filter value then click on the link. This delay could cause users to be misdirected if they accessed the form simultaneously.

Public Sub CTRL225_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
            
            Dim nav As XPathNavigator = MainDataSource.CreateNavigator()
            Dim fieldValue As String = nav.SelectSingleNode("//my:Country", NamespaceManager).Value

            If fieldValue = "Pakistan" Then

                Application.XmlForms.Open("http://sharepoint.xxxxx.net/Sites1/SPptmvpt/TRS3/Tactical%20Action%20Plans/Economic_Crisis%20Management.xml", XmlFormOpenMode.ReadOnly)
            Else
                Application.XmlForms.Open("http://sharepoint.xxxxxx.net/Sites1/SPptmvpt/TRS3/Tactical%20Action%20Plans/Natural%20Disaster_Crisis%20Management.xml", XmlFormOpenMode.ReadOnly)
            End If

        End Sub

Open in new window

0
dgoldieAuthor Commented:
I've rated your answer as B because although you pointed me in the right direction my I found the actuall code from another site - thanks all the same
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
InfoPath

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.