In Access VBA on a Form I want to use two listboxes to sort and reorder a set of field names - vba

I'm trying to create a filter so the user can choose any of 40+ fields to display in a query result that has been dynamically created via VBA.
This is something I see standard in a lot of programs so I figure someone must have code that does it without me reinventing the wheel. Unfortunately I haven't been able to find it online.
Basically when it starts all the field names are listed in the left box and the right box is empty. The user can click a right arrow button to move the fields into the right box or a left arrow to remove them and put them back in the left box. Also the user can use up and down arrow buttons to change the order of a selected field in the right listbox.
Once I have the right listbox populated and ordered correctly I know how to execute the query properly.

If you are unable to find a full example for this then you'll need to work through it step-by-step yourself. Here is an MSDN link for the ListBox control. There are links to the various methods and properties of this control at the bottom of the page.
Essentially, clicking a button (your arrow(s)) triggers the Click event;
In this event you might need to loop through to find the Selected item;
If the listbox is multi-select then you can examine the ItemsSelected collection;
Then you would use the AddItem and RemoveItem methods to move them for right-to-left or left-to-right.
I cannot recall currently whether the Field List option is bound to the table, or whether it just populates the list once when the form is loaded. If it is bound then you would instead need to use the Value List option and use VBA to retrieve all the field-names, and use these to set the RowSource (you may be doing this already).
In either event (Field or Value List) I don't believe the lists can remain sorted automatically (unlike in VB.NET). You will probably need to split the RowSource up into a (dynamic) array, find a simple sort routine to sort the array, and reassign the sorted items as the RowSource.
An alternative would be to create two temporary tables and use ADO (or DAO) to insert and delete rows between them, then use SELECT statements each time to re-populate the lists. This has the advantage that the SELECT can include an ORDER BY clause to sort the lists each time. However, It perhaps involves a little bit more effort (to maintain, and delete, the temporary tables).
You might, however, want to continue your search as I suspect an example is out there somewhere. Good luck.

Related

What is the difference between fields and formfields?

in word pressing alt+F9 can display "FieldCodes"
How can I access this programmatically using vba and pair them with the formfields?
You can access the field code by ? Application.ActiveDocument.Fields(1).Code
And you can access the form fields by Application.ActiveDocument.FormFields(1)
But is there any guarantee's about the indices matching?
Can a formfield ever not be a Field? can a Field ever not be a formfield?
Will changing these away from FORMTEXT have any unintended side effects, or are these basically nice and friendly linking id's / display values allowing you to view them and swap between them with ease?
Edit: I've come up with the following to get the fields Code. I'm still unsure if it's a good idea to edit them or not, or what they represent.
Application.ActiveDocument.FormFields(1).Range.Fields(1).Code
Fields are general objects, they can be :
document's properties (built-in or custom),
mailing / mergemail,
calculation,
form fields,
...
A form fields is an field for inputs.
Take a look at the links in the tag info of word-field, there is a lot of interesting things!
And you can access them by their own collections (press F2 in VBE to use Object Browser).
For Fields the general collection is in Application.ActiveDocument.Fields,
but you can find them in a lot of objects (check with Object Browser!).
Take a look at that answer to have an idea of the other objects in which you can find it! ;)
To my knowledge, there is no possibility nest something inside a FormField, like you can do in a Field.
I'm not sure to understand that question :
"Will changing these away from FORMTEXT have any unintended side effects,
or are these basically nice and friendly linking id's / display values
allowing you to view them and swap between them with ease?"
If you want to create a Form that users can fill, you'll need to stick with FormFields.
If you want to display values at specific places in a document, Fields is the way to go.
I'd even suggest Custom Document Properties for a general use, and MergeMail for Mailings. ;)

Hide specific item in lookup column

My form has lookup column which gets data from another list but I want to remove/hide particular item in the lookup column.
For example; My look up columns gets A;B;C;D;E entries from another list now I don't want to show E in my lookup column .
I can accomplish this if I customize the form in InfoPath but my list(which has lookp column) must be used as "Data sheet view" and InfoPath customization don't work on data sheet view.
Tried using JQuery but didn't work.
Any suggestions ?
Obviously you should never be using jQuery for security related practices. What if a user has javascript turned off?
This question seems to cry out of item level permissions. That said, item level permissions is generally considered a last resort at best type of practice, so I would suggest you first consider whether or not item E could be moved into a different list entirely, which is only viewable by certain parties.

resort able items in listbox in vb.net

how can i turn my listbox to resort able by dragging and dropping in vb.net...
Since user-defined sorting is not an inherent feature of a listbox, you would need to add controls and wire up the events to do this yourself.
Also make sure that the auto-sort property is not set.
Normally people expect a listbox to be sorted alphanumerically by the list contents. That makes finding the value you want much easier.
If you want to show multiple data values to the user and allow them to sort by any of them, you're looking for a datagrid, not a listbox. Grids support sorting, paging, etc.

Best way to select from a list - aren't the two listboxes getting a little old?

How many times have we seen this type of selector:
List Box Selector http://geekswithblogs.net/images/geekswithblogs_net/dotNETvinz/MoveItemsListBox.jpg
I was just about to start creating this in a WinForms app, when I thought that others may have some ideas for doing this better. We need it to sort - so the right hand list will need up/down buttons. But this seems so old school. I love devexpress components, and was thinking of asking them if they would consider adding a component that handles this functionality with a slick UI.
I am thinking that a graphical representation of the objects, and a graphical representation of the listboxes - that would be a more intuitive way to move items around.
Has anyone seen an open source project like this?
If a CheckListBox won't suffice (and it usually will), then the "modern" approach would be to use a ListView or similar component with a "Transfer" column. Render the button inline in that column, one for each row, so that it only takes one click to move an item from one to the other.
You see this everywhere in Vista, usually with hyperlinks as opposed to buttons. Instead of clicking on an item and then choosing an action, you click the action at the item level.
I wouldn't go overboard with slickness as it can impair functionality, but the dual-listbox screen is definitely old-school.
Also, if there's a very large amount of data to manage, it helps to provide a progressive search at the bottom of one or both lists.
I have done this type of selection using (essentially) a single CheckListBox that displays each item as an image. Part of the image looks like a LED, which is on (bright) if the item is selected or off (dark) if it is not selected.
This works well if you have a reasonable amount of data to select from, and also works well in a multi-column format if you can predict that the options will have reasonably similar lengths.
Allow users to drag items in/out of list 2, and also drag to reorder in list2.
(All items dragged out of list2, and dropped anywhere outside the list, get put back into list 1, in their correct place in the list by alphabetical or natural order.)
You can merge the two list boxes into one with the help of groups (LVGF_GROUPID flag): one group for selected and one for not selected.
You can also implement group membership changes with drag-drop between them. This way single drag-drop can move an item into the other group at the appropriate position, saving most/all of the other buttons.
Additionaly the bottom of each group can have one pseudo item with help text (i.e. "Drag items here to...") that is visible only when relevant.

What is the best way for my application to get user input in VB.NET?

My winforms application will display 100 different names, and I will need the user to enter a number 1 through 4 next to each name. I will then store this data.
I know I can use the spreadsheet control, but is there something much simpler that I can use?
Maybe an array of textboxes or a datagrid?
You should be able to use a datagrid and have the first column contain a textbox Item and have a second column display a name. you should also be able to use a listview the same way. Although to be honest you might want a drop down box put in the gridview instead of a text box because with a dropdown/combo box you can make sure they input only a 1-4 because that will be there only options
I would recommend using a DataGrid. This will scale much better than an array of TextBoxes, and should do exactly what you need.
Why not use a numeric up/down control (spinner)?
Something like this would work well:
http://visualbasic.about.com/od/usingvbnet/l/aa082103a.htm
You can embed this in a custom field in a datagrid or repeater if necessary.
You can also just use a combobox:
http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.aspx
Depending on what you are using this for, you might also be able to use something like this:
http://www.codeproject.com/KB/miscctrl/cs_star_rating_control.aspx
Then the user can just click the value.
With either of these options at least your user wont have to enter a value manually and you can set bounds in the control instead of having to validate their input. Your last option should be the user entering a number into a textbox really.