Infopath and VBA

Posted on 2012-09-19
Last Modified: 2012-09-20

I have had some great feedback on how to connect a new InfoPath form
to an Access database using the wizards provided.
Now I'd like to fin out how to communicate with Access in Infopath using VBA.

What VBA code (no wizards) would I use to save data from the following three
InfoPath controls to an Access database with matching columns

Text1 (TextBox)
Date1 (Date)
Number1 (Number)
Question by:murbro
    LVL 84

    Accepted Solution

    I don't use InfoPath, but couldn't you just use standard SQL to do this:

    [Assuming you have a reference in InfoPath to the DAO library]
    Dim dbs As DAO.Database
    Set dbs = DAO.OpenCurrentDatabase("full path to your access db")
    dbs.Execute "UPDATE SomeTable SET Col1='" & Me.Text1 & "', Col2=#" & Me.Date1 & "#, Col3=" & Me.Number & " WHERE YourIDField=" & Me.TheRecordIDValue

    Set dbs = Nothing

    Again, I know little of InfoPath (other than most people avoid it, for various reasons). If your intent is to collect data via email, you're better off either (a) just not doing it, and building a webpage for people to use or (b) using an Excel spreadsheet attached to the email, and processing that when it is returned. I have been involved in projects like this, and we considered InfoPath, but instead went the route of trying to build our own email "form", using HTML email and identifiers/tags in the HTML. It worked _most_ of the time, which is a bad thing in the world of data.

    Author Closing Comment

    Thanks very much for the feedback. I am doing the project for a client who sells medical parts and seems to enjoy Infopath. I am very much an Excel/Access/ person and moved into because a webpage is clearly a much better way of gathering data. I am curious as to why Infopath is used with Sharepoint though. I will post a further question and paste the link below

    Author Comment


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    728 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

    21 Experts available now in Live!

    Get 1:1 Help Now