Autofill a field in a repeating table based on an Access database. - InfoPath Dev
in

InfoPath Dev

Autofill a field in a repeating table based on an Access database.

Last post 07-17-2009 01:45 PM by Hilary Stoupa. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 08-13-2008 01:06 PM

    • sidd9
    • Not Ranked
    • Joined on 08-13-2008
    • Posts 3

    Autofill a field in a repeating table based on an Access database.

    Hello,

    I have an infopath07 template I am working on. I have a main source with a repeating table, with two fields, Client and Job name. These fields are being populated from an Access Database(set up as a secondary source), where each Job name is specific to the Client.

    I have the Client field in my form as a drop-down list being autopopulated from the secondary source.

    What I want to do is search the database for all the Job names for the client I choose and then create a new row in a repeating table, and fill the Job name(in that row) with each job. Then be able submit this back to the database.

    So the end result would be something like this: I choose a Client in the table, then I click a button, this creates a row for each job there is and fills the job name in there, then I submit this back to the database.

    I've found some bits of code but it will only make 1 row and populate it with the first job in the database.

     

    'get external data source

    Dim MasterDataSource As DataSource = DataSources.Item("Master")

    'get values from a couple of fields

    Dim xpath As String = "/dfs:myFields/dfs:dataFields/d:Backup_Tracker/@Company_Name"

    Dim field1 As XPathNavigator = MasterDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager)

    xpath = "/dfs:myFields/dfs:dataFields/d:Backup_Tracker/@Job_Name"

    Dim field2 As XPathNavigator = MasterDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager)

    'clone last repeating table row

    xpath = "/my:myFields/my:group1/my:group2[last()]"

    Dim oldGroup As XPathNavigator = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager)

    Dim newGroup As XPathNavigator = oldGroup.Clone()

    'insert the new group

    oldGroup.InsertBefore(newGroup)

    'set the values of the fields

    newGroup.SelectSingleNode("my:client", NamespaceManager).SetValue(field1.Value)

    newGroup.SelectSingleNode("my:job.name", NamespaceManager).SetValue(field2.Value)

  • 08-13-2008 09:32 PM In reply to

    Re: Autofill a field in a repeating table based on an Access database.

  • 08-14-2008 07:37 AM In reply to

    • sidd9
    • Not Ranked
    • Joined on 08-13-2008
    • Posts 3

    Re: Autofill a field in a repeating table based on an Access database.

    Thank you for the reply. I read through those two articles. I was hoping for some code to automatically do this for me. I'm very new to scripting with vb in infopath. I'm looking for code to loop through a database from a filtered field (I can set up a rule for that easy) and then automatically add a new row and fill out the field for each item it finds in the database (job name).

  • 08-14-2008 11:56 AM In reply to

    Re: Autofill a field in a repeating table based on an Access database.

    Hi -- I have a blog post on this here, but the samples are C# or jscript. Are you already using VB for other code in yoru form? If not, you may want to look at the C# sample and give it a try! If you need to use VB, let me know.

    Hilary Stoupa

  • 08-14-2008 12:36 PM In reply to

    • sidd9
    • Not Ranked
    • Joined on 08-13-2008
    • Posts 3

    Re: Autofill a field in a repeating table based on an Access database.

    Thank you Hilary, this is exactly the example I was looking for. Oddly enough in the meantime I almost found a work around, where I used query fields from a main data source and created a rule to transfer that data into the actual data fields. Where I am stuck now is, I can't figure out how to filter out rows that contain duplicate fields In this case, the job name cannot repeat but the client name can. I do need to use VB.

    I think this work around may just end up being easier to do then doing the whole thing through a secondary data source (and re-writing everything in VB), so if you can help me with filtering duplicates out of a repeating table, I would be fine with that. Either way is fine =]

    Thank you for such a quick reply.

  • 08-14-2008 01:56 PM In reply to

    Re: Autofill a field in a repeating table based on an Access database.

    You can use conditional formatting on your repeating table to do this. I've posted a sample form here. Download it, open it in design mode and preview it. You can add rows and if you enter the same value in the first field in two rows, one will hide. If you look at the table's conditional formatting, you'll see I used preceding-sibling in the filter. Let me know if you have any trouble with the sample.

    Hilary Stoupa

  • 07-17-2009 01:31 PM In reply to

    Re: Autofill a field in a repeating table based on an Access database.

    Hi Hilary,

    Where can I find the sample form you mention in this reply? When I click on it, I get a "Not Found: Forum Not Found" message.

    Thanks,

    RhysAZ

    Filed under:
  • 07-17-2009 01:45 PM In reply to

    Re: Autofill a field in a repeating table based on an Access database.

    Argh! we moved some files around, and it was tough to find. I think it is this sample (updating the original link too).

    Hilary Stoupa

Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.