Vlookup for InfoPath 2010 - sharepoint-2010

I'm trying to develop a calculator type from in InfoPath where the user will be asked to end weight,height, and age. I will then take those values and use them to look up other values that are based on that number. For example if the column headers are Gender, Age, Height, L, M, and S. I want to find the 'L,M,S' values associated with that height. All values in the case are different. So if height were 45, L=-1, M=1, S=2; if height were 50, L= -2, M= 5, S=3.
In excel you a Vlookup with the syntax of :
Dim A as double
Dim Height as double
height = txtHeight.Value
A = Application.WorksheetFunction.VLookup(height, Range("C2:F652"), 2, False)
This would give you the "L" value for the row in which that height is located.
How can I do this in InfoPath? I have seen that are cascading queries you can do for dropdowns and comboboxes, but I want them to be able to type in a value, find a value on a SharePoint list based on that number and then return that number to another text box to use for my calculation.

If the values you want to look up are in a SharePoint list, then you need to create a data connection to that list. Make sure to include all the fields you need. Don't load the data connection at form load.
Let the user enter the height. Create a rule for the height field that fires when the field changes. Add an action that sets the query field for the secondary data source to the value of the height field, then query the data connection. Now the secondary data source contains the record with that height and the fields in the secondary data source contain the values. You can copy the values into text boxes on the canvas.
More details:
After you have set up a data connection to the Heights list, click the Heights field and add a rule by clicking New > Action.
Click the Add button and add an action to set a field's value.
Click the button next to the "Field" text box. If you don't see the top drop-down to select a different data source than the main data source, click the "Show Advanced View" link. Select the secondary data source for the Heights list, open the node for queryFields and the node below that and select the Height field.
Click the fx button next to the "Value" text box, then click "Insert Field or Group" and select the "height" field of the main data source.
OK out of all dialogs.
Add another rule to query for data.
Select the secondary data source to the Heights list.
Add another rule to set a field's value. For "Field" select the main data source field into which you want to copy the looked up value. For "Value" select the secondary data source and drill into the dataFields node until you see the field names. Select the desired field and OK out of all dialogs.
The rules panel should now look similar to this, but with your column names.
Test the form. Enter a valid height into the height field and click out of the field. The corresponding value from the height list will be written into the textbox. The screenshot shows the SharePoint list in the background with the item for heigt "66" highlighted. The value returned to the InfoPath text box "getV1" is from the "V1" field of the SharePoint list.
Hope that makes it clearer.

Related

Control Source of a text boxes set to DCount function - Refresh issue

I'm setting the control source of text fields to return the value of a function (multiple fields with different filtering conditions). The form has a combo box with a list of years: when the user selects a specific year, the on change event triggers a refresh of all the fields.
My problem is the fields don't show any values unless after combo box's On Change events. I have to click on the form/fields before the values start showing up.
I tried to do form refresh & field's requery but doesn't work.
The text field's Control Source is set to:
=SummaryReport("Projects","G","1",[Forms]![frmSUMMARY_REPORT]![cmbYEARS])
What I'm trying to do is when the user selects a year from a drop down, the fields values are updated & displayed by the On Change event - currently they seem to be updated but are not showing unless I click on the screen and that's when values start showing up in each field.
The method to update calculated fields is Me.Recalc (or myForm.Recalc):
https://learn.microsoft.com/en-us/office/vba/api/access.form.recalc
Try this instead of .Refresh.
Also I think the better event to use is After Update instead of On Change for a combo box.

Add header row to listbox

I am using listboxes to display data in userforms in word. However I am not able to set header captions or figure out how to make it possible to click on the header to sort by that column.
GUI.Search_ListBox.Clear
GUI.Search_ListBox.ColumnCount = 5 ' Columns
GUI.Search_ListBox.ColumnWidths = "120;80;70;120;300"
GUI.Search_ListBox.ColumnHeads = True
'GUI.Search_ListBox.RowSource = "Hello;gkjfl;hsjgh;hdfjhgkj;fdjghjkdf" 'here it fails!!!
With VBA, simply set the ListBox.ColumnHeads Property to True.
Alternatively, you can also change the setting in the ActiveX control's Properties dialog:
If the button is disabled on the ribbon, you'll have to enter first.
More Information:
ListBox.ColumnHeads Property (Access)
EDIT:
You need to specify the headings in the rowsource:
Column headings are enabled and either field captions, field names, or the first row of data items are used as column headings.
I just create another list box and place it right above the primary listbox, make it flat etc. Then use the header row as the row source. That way any calculations made in the header row shows on the form as well.

How to make a total column that updates automatically in Access.

In access I am trying to get my total value to be equal to the sum of the all of the different values where the order number is the same.
My current code is as follows;
= SUM( Forms![OrderLine]![Total] ) Where( Forms![OrderLine]![OrderNo] = [OrderNo] )
This however gives me an error. How else would this be done?
Thanks
It sounds like you have an Order form and an OrderLine subform. Add a Form header/footer to your OrderLine form and put a text box in the footer. Put a SUM function in the Control Source of the footer text box to generate the aggregated value you need from the order line item rows.
On your main form, set the Control Source of the text box you want to display the order total equal to the name of the invisible text box in the subform. The control source on the main form text box will resemble SubformControlName.Form.AggregateTextBoxName.
You may need to play with the visibility settings of the header/footer, text box, form view mode, etc. to get the presentation you want, but this works even with the subform in datasheet view. The key is to get a text box somewhere on the subform to calculate the value you need on the parent form and then reference it inside the subform control from the parent form.

How to use the value not displayed by a dropdown when connected to access database

My program uses a database in access which consists of BreedID and BreedName. I have a dropdown box in vb.net which shows the name for the user to select, however in my code I would like to store the ID related to that name so that I can send it over to the access database using oledb. Currently this is what it looks like:
Dim BrVar As String = Breed.SelectedItem.Text
But that isn't working! Please help!
You can add hidden columns to your dropdown box, it may already exist. The first column in a dropdown box is column(0) and you can set the width to 0cm. This can be for the ID value. Leaving column(1) for the Name value.
Then you can use Breed.SelectedItem.column(0)
The first thing to do is on the Data tab set up your rowsource to SELECT both the BreedID and BreedName fields (in that order). Then make sure bound column is set to 1.
Then on the Format tab set Column Count to 2 and Column Widths to 0;1.
That will have the result of displaying the BreedName field but using the BreedID field as the value of the combo box.
Use Dim BrVar As Long = Breed.SelectedItem to get the value of BreedID.

Add second line when a column is full from text length ultraWinGrid

Is there a way to automatically add a new line or something when a column in my ultraGrid is full? Sometimes when i load some text into a column in my ultragrid it has a longer value length than the available column field, as a result some text stays hidden. So i want when this happens to show the rest of the text in another line. Is this possible in vb.net for ultrawingrid?
You could set the CellMultiLine property as in the example below. (supposing you have one band and the column with the long text is the second one)
UltraGrid1.DisplayLayout.Bands(0).Columns(1).CellMultiLine = DefaultableBoolean.True
UltraGrid1.DisplayLayout.Bands(0).Columns(1).VertScrollBar = True
UltraGrid1.DisplayLayout.Override.DefaultRowHeight = 100
The next two lines are optional, but they serve the purpose to show immediately the column with a different height and with a vertical scrollbar