Trouble with drop downs and auto-populating - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Trouble with drop downs and auto-populating

Last post 01-13-2005 06:27 AM by ptgrayson. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 12-07-2004 02:05 PM

    Trouble with drop downs and auto-populating

    Hello,
    I am a police officer with the city of Winter Haven Florida and have been creating our new report writing system with infopath. The project is approximately 90% complete but I am having trouble with some of the advanced features. (or at least advanced for me.

    I don't know what level of assistance I may get but I was hoping that someone may have had the same propblem I'm having and beat it. Any assistance would be greatly appreciated.

    To set the stage the report consists of a main section which is in all reports. Then has multiple optional sections with a repeating section inside of them so the officers can ad as many people, suspects, property, etc as they need to.

    The form is done and works great. However there are a few things that I would realy like to see.

    1. The first problem is I have a repeating table so the officers can list the types of offenses. I have one cell which I have changed to a drop down. it is linked to an access data base which I wrote for the Florida State laws. I wanted a another cell to be automaticly filled with the statute number that matches the offense I have selected. I got it set up and it works following your examples, However it only works for the first selection. When I add a second row sometimes it works correctly sometimes it doesn't. But needless to say once I add the second row any others show the same statute number in the auto-populated cell. This is what steps I took.

    1. Create the repeating table.
    2. Change one of the fields to a drop down.
    3. Link that drop down to the database.
    4. set a rule to fill the statute number field.
    5. opened the filter and added a filter so the crime = the database name for it.
    I noted that when I opened the filter there was a long filter there I had to remove that one to get it to work at all.

    it looks like this: rule1: @statutenum=@statute[description=charge}
    filter: description=charge


    Can you help?


    The second issue is this I have option/repeating sections for listing suspects. I also have optional/repeating section for writing the charging documents. I there a way to get the suspects data to auto populate the fields in the charging document from the suspect section so that the first suspect goes in the first charging document, the second on goes in the second and so on? I could do it with drop down boxes but I would rather have it do it automatically.


    Any help in this issue would be great.

    Thanks in advance,

    Ofc. Richard Ganey
    Winter Haven Police Department
    res072xc@gte.net
    863-287-1952
  • 12-29-2004 08:46 AM In reply to

    Re: Trouble with drop downs and auto-populating

    I am also having the same problem as your first problem. Hopefully we can get an answer soon from one of the MVP's.

    Todd Grayson
    US Army
  • 12-30-2004 01:09 PM In reply to

    Re: Trouble with drop downs and auto-populating

    I think I may have figured out a solution to the first problem...I use VBScript code to accomplish the task. Basically, the code is written into the OnAfterChange event of the drop down list box, so that it executes/updates every time a change is made to a drop down in any of rows of the repeating table. I use two data sources: First is the main data source which is where the fields that the controls (the drop down and the text box) bind to are located. Second is a secondary data source which contains the statutes table.

    Dim test
    Dim i
    Dim temp
    Dim temp2
    Dim queryString


    'Gets the data for the rows in the repeating table (the repeating table is bound to group2)
    set test = XDocument.DOM.selectNodes("/my:myFields/my:group1/my:group2")

    'the code below loops through each row of the repeating table and for each drop down that is not blank or null, it queries the secondary data source with the offenseID from the drop down and finds the corresponding statute, then puts that statute number into the text box in the form control

    for i=0 to (test.length-1)

    'get the offense number from the drop down
    temp = test.Item(i).getAttribute("my:offense")

    'make sure the offense isnt blank or null...important!
    if (not(IsNull(temp)) and temp<>"") then

    'build the string which will form the query
    queryString = "Select * from StatuteTable where OffenseID=" + temp

    'query the secondary data source
    XDocument.DataObjects("StatuteTable").QueryAdapter.Command=queryString
    XDocument.DataObjects("StatuteTable").Query()


    'get the resulting data from the secondary data source after it has been queried
    set temp2 = XDocument.DataObjects("StatuteTable").DOM.getElementsByTagName("d:StatuteTable")

    'Set the statute field in the main data source to the value found in the secondary data source
    test.Item(i).setAttribute "my:StatuteTextBox", temp2.Item(0).getAttribute("StatuteNumber")

    end if

    next


    *Note: your XPaths for accessing the data sources may differ depending on how you set up your form (started from scratch, started from a data connection, etc) as well as the differences in how you named your tables and/or fields...if you have any questions, feel free to ask
  • 01-06-2005 01:14 PM In reply to

    Re: Trouble with drop downs and auto-populating

    Ok, I got your code working, but now I have a different problem. One of the auto-populated values gets a NaN error when I try to do a simple multiplication formula. The other auto-populated numbers multiply just fine. Any ideas?

    Todd Grayson
    US Army

    quote:
    Originally posted by crashoverride

    I think I may have figured out a solution to the first problem...I use VBScript code to accomplish the task. Basically, the code is written into the OnAfterChange event of the drop down list box, so that it executes/updates every time a change is made to a drop down in any of rows of the repeating table. I use two data sources: First is the main data source which is where the fields that the controls (the drop down and the text box) bind to are located. Second is a secondary data source which contains the statutes table.

    Dim test
    Dim i
    Dim temp
    Dim temp2
    Dim queryString


    'Gets the data for the rows in the repeating table (the repeating table is bound to group2)
    set test = XDocument.DOM.selectNodes("/my:myFields/my:group1/my:group2")

    'the code below loops through each row of the repeating table and for each drop down that is not blank or null, it queries the secondary data source with the offenseID from the drop down and finds the corresponding statute, then puts that statute number into the text box in the form control

    for i=0 to (test.length-1)

    'get the offense number from the drop down
    temp = test.Item(i).getAttribute("my:offense")

    'make sure the offense isnt blank or null...important!
    if (not(IsNull(temp)) and temp<>"") then

    'build the string which will form the query
    queryString = "Select * from StatuteTable where OffenseID=" + temp

    'query the secondary data source
    XDocument.DataObjects("StatuteTable").QueryAdapter.Command=queryString
    XDocument.DataObjects("StatuteTable").Query()


    'get the resulting data from the secondary data source after it has been queried
    set temp2 = XDocument.DataObjects("StatuteTable").DOM.getElementsByTagName("d:StatuteTable")

    'Set the statute field in the main data source to the value found in the secondary data source
    test.Item(i).setAttribute "my:StatuteTextBox", temp2.Item(0).getAttribute("StatuteNumber")

    end if

    next


    *Note: your XPaths for accessing the data sources may differ depending on how you set up your form (started from scratch, started from a data connection, etc) as well as the differences in how you named your tables and/or fields...if you have any questions, feel free to ask


  • 01-11-2005 01:58 PM In reply to

    Re: Trouble with drop downs and auto-populating

    Does the data need to be converted to a different form before multiplying?

    ex: CInt(data)*num
  • 01-12-2005 06:49 AM In reply to

    Re: Trouble with drop downs and auto-populating

    The result is stored as double. The funny thing is that two of the three number work. Only the last one gets the error. I thought that it might be reading in the null character at the end of the string, but I am not sure.

    Todd Grayson
    US Army

    quote:
    Originally posted by crashoverride

    Does the data need to be converted to a different form before multiplying?

    ex: CInt(data)*num

  • 01-13-2005 06:27 AM In reply to

    Re: Trouble with drop downs and auto-populating

    I got it working. I just needed to convert the string value to a double value. Thanks for the help.

    Todd Grayson
    US Army

    quote:
    Originally posted by crashoverride

    Does the data need to be converted to a different form before multiplying?

    ex: CInt(data)*num

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