Add header row to listbox - vba

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.

Related

Getting a Value if a Field and Record number is known?

Good Evening,
I am working on a Combo Search Form that is designed to search for information by criteria. The form has a combo box containing field values and a text box beside it. The selection of a field value in the combo box will fill in the text box beside it with the relevant information for that record, all the relevant information is contained in the PetTable.
I have managed to get the combo box to display the fields from the PetTable by setting the rowSource to PetTable and the sourceType to Field List... however that's where I hit my dead end.
In the Text Box beside the combo-box I tried grabbing the value of the combo box and putting it into the textbox by making the Text box control source "=ComboBox", however this just created a textbox which has a literal text string to that of the combo box.
My next thought was to make the text box Control source "=PetTable.PetComboBox" my thought was that the PetTable references the table with my information and the "PetComboBox" becomes the field a need to get. This did not work either and gave a #Name error"
What should be happening is: In the Combo-box if I selected [Pet Name], I would hope that the textbox beside it becomes "Fido" but instead it also becomes [Pet Name].
Any and all help would be appreciated!
Thanks
Desired Effect
What you need to do is to change the Row Source Type of the Combo Box to "Table/Query". Then in the "Row Source" click on the "..." to open up the Query Builder. Select the table that you want. Add the columns that you want. I would suggest the table's primary key PetID, and then any other fields - in your case at least PetName. You may also want to sort by PetName to make it easier for the user to scroll through. Close the Query Builder and save the changes. Change the combo box's ColumnCount to 2, and set the Column Widths to be "0cm;6cm" (setting the first column to have a width of 0 means that it is not displayed to the user).
Now move to you TextBox, and set the Control Source to be:
=[Combo0].Column(1)
Note that columns in a combox box are 0-indexed, so the first column is column 0, the second (in your case containing PetName) is column 1.
As you actually want to show the field names, rather than the data in the combo box, then you will need to set the RowSourceType to be "Field List", and then select the table name as the RowSource.
You will then need a small piece of VBA to lookup the value of that field in the table for the current record:
Sub sListFieldData()
If Not IsNull(Me!Combo0) Then
Me!Text2 = DLookup(Me!Combo0, "tblPet", "PetID=" & Me!PetID)
Else
Me!Text2 = ""
End If
End Sub
And you will then need to call this procedure in the combo box's AfterUpdate event (to catch when it has been changed by the user) and also in the form's Current event (to catch when the user moves between records):
Private Sub Combo0_AfterUpdate()
Call sListFieldData
End Sub
Private Sub Form_Current()
Call sListFieldData
End Sub
Regards,

How do I use ONE control source with MULTIPLE combo boxes from a USER FORM, in Access?

I am currently developing A quote sheet for work, I have 21 Combo boxes that are all populated by the same row source. The problems that I am having are When all my combo boxes are set to the same control source all the list values in the combo box are filtered and set to one value. For example combo box 1 is selected and prep is selected now the other 20 combo boxes are set to prep, and I can't select the other options. Now if I have no control source for my combo boxes than previous example works. If I select combo box 1 and set it to prep then I can select combo box 2,3,4... and put any value I want for each one. I want to be able to have each combo box with its own value.
The reason I am wanting the combo boxes to have the same control source is so when a combo box has a selected value it will add a new record to my table. So if 10 combo boxes have values selected then there will be 10 new rows added to my table when I click my add record button.
I am thinking a maybe having a loop do the work, but am not to familiar with with using vba to run sql??
You can't use the same control sources to generate multiple records on the same form. They must be unbound. At least, I don't know how to make that work the way you have it set up, but can still help.
Delete the control sources but keep the row sources.
You will need a query to save the values to your table:
INSERT INTO MyTableName ([MyFieldName]) VALUES ('[ComboboxValue]');
Copy this code and paste in query builder. Overwrite "MyTableName" and "MyFieldName" with the appropriate object names for where you want a single combobox value to be saved. It only adds one row at a time. [ComboboxValue] will be the parameter we use to pass each combo value to the query to execute.
Name the query whatever you want and save it. I will use the placeholder "MyQuery," make sure you update it!
Create a command button on your form, and in its On Click event, paste in this VBA code (you will need to update the combobox references where I use Me!ComboboxName):
Dim qdf As DAO.QueryDef
Dim combo As String
Set qdf = CurrentDb.QueryDefs("MyQuery")
combo = Me!Combobox1Name
qdf!ComboboxValue = combo
qdf.Execute
combo = Me!Combobox2Name
qdf!ComboboxValue = combo
qdf.Execute
'Copy those three lines for each combobox, adjust your combobox references accordingly,
'or use a loop
'End your procedure like this:
Set qdf = Nothing
If you are using a multi-column combobox, you may need to adjust the reference from Me!Combobox1Name to Me!Combobox1Name.Column(1).

Excel VBA mulitiple checkboxes

is it possible to create listbox with multiple checkboxes in one row (Excel VBA)?
Thanks
Kamil
I'm not sure I understood your question fully, but I'll elaborate on ListBoxes as much as I can.
First things first: Checkboxes and ListBoxes are different objects in Excel Userforms. The first is the little box that returns a "true/false". The second is a list of items which can be chosen. Clicking in a Checkbox will make the tick mark appear/disappear (or fade if tristate is enabled), while clicking a Listbox row will turn the listbox row "blue"/"white" (or whatever color is being used for the selected rows). In both elements, clicking is a way to toggle between True and False.
While a checkbox only allows for a single information to be marked as True or False, a Listbox allows you to select entries out of a list. That list may be inserted through code (.AddItem method) or passed from a range (.RowSource property)
ListBox objects allow for multiple columns of data to be attributed to one row element, but each row is an entire element (which means you cannot pick the element on row 3, column 2 - only all of row 3). The number of columns is established using the ColumnCount property.
By changing the value of the MultiSelect property, you'll allow the user to select multiple or single row elements simultaneously on your Listbox. Using the Selected( RowIndex ) property, you can check whether or not an item is currently selected (returns True/False). Remember that row indexes start at 0.
Finally, if you're using the MultiSelect property set to fmMultiSelectSingle and have a single column (as far as I know), the Text property can be used to return the selected item's value.
An easy example of a listbox is in Excel can be found at File > Options > Customize Ribbon (or something like that). There are two listboxes, one (on the left) with the visible items and another with the available items. A pair of command buttons is used to move items between boxes. That's a simple application you can likely find already setup online.
Am I on track to answer your question?

Hide Row from dev gridview vb.net

I want to remove/hide this row (in orange) from the grid, I don't know what this row mean.
Thanks.
I see that the auto filter row feature is enabled on you screenshot. This feature row allows data to be filtered on the fly - by typing text within a row.
To disable this feature set the GridOptionsView.ShowAutoFilterRow property to false.
You can also restrict this option from activating by end-user via hiding the "Show Auto Filter Row" check item within the Column Header Context Menu. To do this, just set the GridOptionsMenu.ShowAutoFilterRowItem property to false.

Vlookup for InfoPath 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.