Solved

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

Posted on 2010-08-25
7
2,701 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

19 Experts available now in Live!

Get 1:1 Help Now