Solved

Can I Get Data from an InfoPath Form Into Excel or Access with VBA?

Posted on 2010-08-25
7
2,640 Views
Last Modified: 2013-11-27
Someone created an InfoPath form which various people e-mail to me to send me information. The problem is, we don't have MOSS, and I can't do anything with the data in the form unless I want to copy and paste each field into either a spreadsheet or a database.

I am hoping there is a way to extract the data from the InfoPath form into Excel or Access using some VBA code.

Does anyone do anything like this?
0
Comment
Question by:Rex85
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:Juice841
ID: 33524357
I assume you are getting the form.xml files back from each submitter.  

If so you can import the form results into Excel by selecting the [Data] tab then selecting [Other Sources]-[From XML  Data Import]

J
0
 

Author Comment

by:Rex85
ID: 33524400
I can export them to Excel yes. I am receiving the Form.xml file.

I was hoping there was a way to code it so that executing a macro from Excel or Access could extract the data from the form into a table in it's proper place.

0
 
LVL 1

Accepted Solution

by:
Juice841 earned 500 total points
ID: 33525655
Here is an example....

1. update the ReadXMLIntoCells sub to match for infopath xml nodes
2. add column headers to your sheet
3. you will need to include a reference in you excel vba for MS XML ([Tools] -[References]

J

Private Sub CommandButton1_Click()
    Dim iCount
    
    'for a max set of rows
    For iCount = 1 To 1000
        
        'If this is an empty row then read a file and import
        If IsEmpty(Cells(iCount, 1)) Then
            ReadXMLIntoCells (iCount)
            Exit For
        End If
        
    Next iCount
    
    
End Sub

Private Sub ReadXMLIntoCells(i)
    Dim doc As MSXML2.DOMDocument30
    Dim mnode As MSXML2.IXMLDOMNode
    Dim sFile
    
    'create xml doc
    Set doc = New MSXML2.DOMDocument30
    
    'get a filename from the user
    sFile = Application.GetOpenFilename("XML Files (*.XML), *.XML", , "Open an xml file...")
    
    'loa the file from the user
    doc.Load (sFile)
    
    'the cells based on node name in infopath...defaults are my:field.....
    Cells(i, 1) = doc.SelectSingleNode("//my:field1").Text
    
    Cells(i, 2) = doc.SelectSingleNode("//my:field2").Text

End Sub

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 28

Expert Comment

by:clayfox
ID: 33535428
The other option is to have the data stored in a database rather than the indivdual forms.

Then you can connect Excel to the database and all of your records are aggregated.
0
 

Author Comment

by:Rex85
ID: 33535514
I would prefer the aggregated database approach. I am not locked into Excel necessarilly. I am still working with the code Juice841 provided.

Would the code to store the Infopath data in a database (Access perhaps?) be similar?

Rex
0
 
LVL 28

Expert Comment

by:clayfox
ID: 33536635
You can utilize a database without any code, completely codeless.

You would need to redo the form as a database type form (linked to a table). Or get a third party tool like www.qdabra.com provides.
0
 

Author Closing Comment

by:Rex85
ID: 33648685
Thanks.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now