Forms :: Move Multiple Items In A Listbox

Jul 13, 2013

I have a form with a listbox in which users should be able to move the items up and down. The listbox has 4 columns and multiple selection is enabled.

For a NON multiselect box I have it working, and also for a multiple selection box but in that case it works only for one row at a time.

For a NON multiselect listbox:

Code:
cmdDown_Click()
Dim i As Integer
Dim t1 As String, t2 As String, t3 As String, t4 As String
i = selectie.ListIndex
t1 = Nz(selectie.Column(0, i))
t2 = Nz(selectie.Column(1, i))

[Code] ....

You can select an item and then press "Down" as many times as you want to put the items as "down" in the list as you want it to be.

Multiselect listbox

This code also works for a multipleselection listbox when one item is selected, however, after you press "down" the item is still selected (highlighted) as the code reselects is (last line) BUT the value of selectie.listindex apparently is set to "-1".

Pressing "Down" again generates an error (i = -1). I can evade the error by adding "if selectie.listindex <=0 then exit sub", but that doens't fix the problem that the only way I can manage to reset the listindex to the new "position" of the item is to click on it again and THEN press "Down".

To fix this and be able to press "down" multiple times listindex should be set to the new value.

Adding a "me.selectie.listindex = i -1" doens't work (error), it seems like this value is readonly.

I can't find a way to "simulate" a mousepressed selection and really set the listindex.

The other problem is of course that this code doens't support moving multiple items at once: listindex points to the last selected item, but only one.

So, I tried another piece of code to move multiple items, not using listindex (since that resets to -1), but I run into another problem

Code:
Private Sub cmdDown_Click()
Dim var As Variant
Dim i As Integer
Dim n As Integer
Dim t1 As String, t2 As String, t3 As String, t4 As String
n = Me.selectie.ItemsSelected.Count

[Code] ....

The problem with this is: I can select multiple items and press "Down", but the problem now is that the selection is lost as soon as the code removes the first item, and the 2nd loop skips the if selected(i) = true (nothing is selected anymore).
The me.selectie.selected(i+1) = true doens't work since that would only reselect the first item after moving it.

The code "forgets" which items were selected and moves only one item...So I guess I need to put the indexnumbers in memory while moving the items.

I have been searching a lot, but can only find VB-solutions. In VB it's a lot simpeler using f.e. the .list property of a listbox, which is not available in MSAccess

The solution I'm thinking about is:

- set an array with the numbers of selected items
- put indexnumbers of the selected items in the array (f.e. 3 and 4)
- move items based on the indexnumers in the array
- when moving an item update the indexnumber in the array (3>4, 4>5)
- after moving all items reset the selection based on the array

It occurred to me then if I'm going to use an array anyway, I might as well load all items in an array, do the "resorting" and the reload the items in the list from the array. Might be more straightforward?

Btw...It seems VB has a simple solution to moving items: listbox.list(i) = listbox.list(i+1) or something like that moves an item. Even Excel seems to have this property but not MS Access!

View Replies


ADVERTISEMENT

Move Items From Listbox To Other Listbox

Jul 16, 2006

Hello everybody,

Hopefully somebody can help me on this one. I searched the whole internet and access forums, but I didn't find the exact solution for my problem.

I've got a table with students, a table attendance, where I now only save the students who are absent, but I would like to save also the students who are PRESENT (at the same time).
I've got a combobox where I filter the Class, which then updates a listbox with the students from that class. What I do now is select the students from the listbox and then press a save button and it saves the records to the table absence with STATUS: ABSENT.

I would like to save the NON selected students also in that table, but with PRESENT in the column STATUS.

I thought of making another listbox next to it, where after selecting the absent students, they wil apear and disappear in the PRESENT table so I can store all the information.
But the only problem is that I can find this solution when the listbox is populated by a list of values instead by a table or query. And the other solution is to store the temporary data into 2 different tables, but that's not working for me because it's a multi user database and everything will be messed up.

Hope that someone can help me, I will be very happy.

View 4 Replies View Related

Forms :: Remove Multiple Selected Items From Listbox

Jul 24, 2013

How do I remove multiple selected items from listbox.

Noticed it is a table/query listbox, not value list.

Remove selected.zip

View 1 Replies View Related

Forms :: Move Selected Items To And From Listboxes?

Dec 11, 2013

I have 2 Listboxes the first list is based on a query I need to select items from this box or part of each item and move to another listbox. the items in the second listbox will be used in a report. I have previously posted on another forum with no real luck fyi. the query is put straight in the RowSource.

View 3 Replies View Related

Modules & VBA :: Remove Multiple Items From ListBox

Aug 6, 2013

I'm trying to setup a listbox so that multiple items may be selected and removed at once. The Listbox Multi Select property is currently set to "Extended" and I have the following code on the onclick event of a command button:

Code:

Private Sub Command12_Click()
Dim i As Integer
For i = List10.ListCount - 1 To 0 Step -1

[Code]....

I have tested selecting 4 or so records on the list box and then pushing the remove button but it seems that the only record that is removed is the selected record that is furthest down on the listbox. The other selected records become unselected and must be reselected in order to continue removing records.

View 1 Replies View Related

Modules & VBA :: Updating Multiple Items In A Listbox

Jan 9, 2014

In my form I have the listFunctions list box set to Multi Select "Extended" in the following code contains a line to execute a query based on the selected items in a listbox. but for some reason instead of only changing the selected items it is changing all items in the listbox. I stepped through the code and it is looping the correct number of times based on the amount selected but is still changing all.

eg.if I select 3 items from the list, it loops through the execute 3 times.but the total 6 items will change.

Code:

Private Sub cmdEdit_Click()
Dim varItm As Variant
Dim sSQL As String
Dim ssSQL As String

[code]...

View 1 Replies View Related

Modules & VBA :: Listbox Setup With Option To Select Multiple Items

Jan 7, 2015

I am trying to set up a listbox with an option to select multiple items (I have done this and tested it with debug.print and it seems to work). I am then building a filter statement with VBA. I want to then use a button to add this statement to the filter in a subform with (a datasheet design), and then requery it.

My code below seems to be working in part. But I am getting all the items at times. Seems to work consistenly when selecting one item only, but I can't see anything wrong with my 'OR' statements when I debug.print.

Private Sub Command176_Click()
Dim i As Integer
Dim strFilter As String
Dim blnFirst As Boolean
i = 0
If Me.List163.ItemsSelected.Count = 0 Then

[Code] .....

View 3 Replies View Related

Forms :: How To Move Item In Listbox Up And Down Access VBA

May 21, 2014

I have a list box contains 10 times . I have UP and Down buttons to move item up and down. My VBA works only if i set listbox multiselect property to 'None'. For the multiselect=simple option it throws error like in valid use of null in this line of code :

sText = lbfNames.Column(0, iIndex)

My VBA

Code:

Private Sub cmdUP_Click()
Dim sText As String
Dim iIndex As Integer
iIndex = lbfNames.ListIndex
'check: only proceed if there is a selected item

[Code] ....

View 8 Replies View Related

Forms :: How To Move Up And Down Selected Item In Access Form Listbox

Feb 10, 2014

I've designed access form with one listbox and added 'up' and 'down' buttons to move up and down the selected item in the listbox. i.e from its selected position to one item up when 'up' button clicked and same as one item down when down button is clicked. Any VBA code will do this functionality?

View 7 Replies View Related

Forms :: Count The Number Of Items Selected In Listbox?

Nov 1, 2013

I'm creating an employee audit database, and, in the audit form, the user (ie. supervisor) can select a number of items from a listbox. Each item selected corresponds to an error that the employee has made, and, as such, the employee's Audit Score has two points deducted for each item that is selected.

Incidentally, there are other, solitary elements to the form, but this particular listbox houses a collection of items that are related under a single category.

The score is displayed at the bottom of the form, and it needs to update in real-time.

The problems that I am encountering are that I am unable to count the number of items selected and then I am unable to multiply that count by 2 (the point-value of each item on the list.)

View 2 Replies View Related

Forms :: Concatenating Listbox Items - Column Data

Mar 18, 2013

I saw the following code on the forums...

Dim i As Integer, c As String
With Me.ListBox.Column(0)
For i = 0 To Me.ListBox.ListCount - 1
c = c & Me.ListBox.ItemData(i) & ", "
Next
End With
c = Left(c, Len(c) - 2)

This works great!! Now I am trying to concatenate the column 3 of the listbox.

Tried to use the code below (pointing to the second column) but it always returns the first column data.

'Dim i As Integer, d As String
With Me.ListBox.Column(2)
For i = 0 To Me.ListBox.ListCount - 1
d = d & Me.ListBox.ItemData(i) & ", "
Next
End With
d = Left(d, Len(d) - 2)

ItemData does not allow pointing to my 3 column of the listbox.

View 4 Replies View Related

Forms :: Using ComboBox To Look-up A Multivalued Field And Select Items In Listbox?

Jul 21, 2014

I'm creating a Form called Pharmacy where I can select a [Diagnosis] from a combo box in the form. This combo box source references a table called tblDiagnosis where each Diagnosis also has a multi-valued field called [Indications].

The Pharmacy form also has a multi-select listbox with all possible Indications. I would like to write a VBA code such that when a Diagnosis is selected, the Indications for that Diagnosis are automatically selected/highlighted in the listbox on the form as well.

As such, by selecting a Diagnosis, all the indications attached to that Diagnosis will automatically be selected; however, if additional indications are needed, they can still be selected afterward.

I know that there is a function Me!Listbox.Selected(i) = True, where i is the row of the entry in the listbox. However, the i in the listbox does not correspond to the ID of the Indication. I think that if there is a way to select listbox items by name, that would be much more efficient.

The reason I have a listbox, is because this listbox of Indications then references another table called tblDrugs where all drugs that are approved for the selected indications selected are filtered and displayed.

View 1 Replies View Related

Forms :: Right Click Listbox To Copy Selected Items To Temp Table

Mar 7, 2013

I'm trying to create a right-click event on a listbox that will copy selected listbox item(s) to a temp table. So far, I've got this code to acknowledge the right click:

Code:
Private Sub List0_MouseDown(Button As Integer, Shift As Integer, X As Single,
Y As Single)
If Button = acRightButton Then
MsgBox "You pressed the right button."
End If
End Sub

Problem is the selected item on the list box doesn't move until after the mouse down event so whatever code I would run would involve the wrong record(s).

I'm using Access 2000 and 2003. How to get the the correct record selected on mouse down, or point me to a working example of right-click functionality on a listbox.

View 4 Replies View Related

Linking Multiple Items From A Table To One Item In Another In Forms

Mar 4, 2015

I have what should be a really simple database to build. In table tbl1PlanHdr is the header item. Many items in tbl2MaintItem will then be allocated to each header. MaintItems items will be allocated to more than one Header.

I want to set up a form that has the tbl1PlanHdr as the main part of the form and tbl2MaintItem as the subform. Possibly as a datasheet, or continuous form.

I need the ability to update items in the subform back to the orginal table.

I have a relationship of one to many from the tbl1PlanHdr to tbl2MaintItem using the primary key in tbl1PlanHdr.

But should this be a one to many from tbl2MaintItem to tbl1PlanHdr

The end result required is to be able to get a data dump of all the tbl1PlanHdr items with the corresponding tbl2MaintItems items.

View 8 Replies View Related

Move A Selected Listbox Row Down 1 Row

Mar 24, 2006

hi
i apologize if this question has been answered before. i have looked at numerous others in the 'listbox' search box, but not had any success in adapting the answers to what i need.

i have a form A with a listbox of 1,400 rows

i then select maybe the 10th row down on the listbox, and

a new form B opens with information pertaining to the listbox row selected
form A changes its visible value from true to false

i do my editing on form B

now what i would like to do is, on form B click a next button and for

form B to close
form A to be visible again, and the next row (11th) on the list box be highlighted
form B to open again but with pertaining to the next listbox row (11th) selected
form A to not be visible

any help would be very much appreciated

View 1 Replies View Related

Move Records On ListBox

Mar 29, 2006

Here's a tough one that has been driving me crazy! (Probably easy, but I don't want to admit it!)

I have a form with a listbox called "lst_exclist". The recordsource for this listbox is the following query:

SELECT tbl_collexcludereasons.priority, tbl_collexcludereasons.excname, IIf(tbl_collexcludereasons.enabled=-1,'Enabled','Disabled') AS enabled, tbl_collexcludereasons.priority FROM tbl_collexcludereasons ORDER BY IIf(tbl_collexcludereasons.enabled=-1,'Enabled','Disabled') DESC , tbl_collexcludereasons.priority;

Which basically gives me this with dummy data:
2 PIPELINE ENABLED
3 HELLO ENABLED
5 GOODBYE ENABLED
1 BAD DISABLED
4 GOOD DISABLED
6 LAST DISABLED

I had two command buttons, one up arrow and one down arrow. The up arrow is supposed to move the selected record on the listbox up by exchanging the next lesser priority number with itself. The down arrow does the same. The DISABLED records are supposed to be ignored on the move up and move down procedures, meaning only ENABLED records are allowed to exchange priority numbers, and thus move up or down on the list. I tried the following code:

Me!lst_exclisthidden = Me!lst_exclist

DoCmd.SetWarnings False

Dim startingnumber As Integer
Dim endingnumber As Integer
Dim nametochange As String
Dim getchangerst As DAO.Recordset

If IsNull(Me!lst_exclist.Column(0)) = True Then
MsgBox "Please choose an entry on the above list to move.", vbCritical, "Error"
Exit Sub
Else
End If

If Me!lst_exclist.Column(2) = "Disabled" Then
MsgBox "There is no need to move a disabled selection, please enable the selection to change it's priority.", vbCritical, "Error"
Exit Sub
Else
End If

startingnumber = Me!lst_exclist.Column(0)
nametochange = Me!lst_exclist.Column(1)

endingnumber = startingnumber + 1

If Me!lst_exclisthidden = acLast Then
MsgBox "You cannot move the bottom selection on the list down, please choose another one.", vbCritical, "Error"
Exit Sub
Else
End If

While DCount("*", "tbl_collexcludereasons", "Priority = " & endingnumber & " and Enabled = -1") = 0
endingnumber = endingnumber + 1
Wend

DoCmd.RunSQL "Update tbl_collexcludereasons set tbl_collexcludereasons.priority = tbl_collexcludereasons.priority - 1 " & _
"Where tbl_collexcludereasons.priority <= " & endingnumber & " and tbl_collexcludereasons.priority > " & startingnumber

DoCmd.RunSQL "Update tbl_collexcludereasons set tbl_collexcludereasons.priority = " & endingnumber & " " & _
"Where tbl_collexcludereasons.excname = '" & nametochange & "'"

Me.Refresh

Me!lst_exclist = endingnumber

Me!lst_exclisthidden = Null

DoCmd.SetWarnings True

But it seems to loop when it gets the the area it is checking for numbers because the highest records is disabled, so it's ignored. How can I make this work? Please help!

Thanks

Vassago

View 1 Replies View Related

Move Data From One Listbox To Another

Nov 27, 2013

I have two particlular listboxes in an Access Form the first is named listEmp and the second is listAllocated

The source of the first is a query which is based on previous combo boxes.

How can I move selected or all items from one box to another and back if needed.

I need the items moved to be removed from the original box so the data is only in one or the other box.

Please include any VBA that may be needed.

View 14 Replies View Related

Forms :: Populating Text Box Upon Selecting Multiple Items In Combo Box?

Nov 28, 2014

Now I have a combo box "cbo_items" and a text box "txt_selectedItems", I want to populate text field with items selected from the combo box, every time i select an item it appears in text box and to be separated with comma, so text box appears like this ( item1, item2, item3), and after finishing the whole thing the result appears in lable "lbl_result" as "total items selected: 3 items".

View 1 Replies View Related

Forms :: Filtering Records On Multiple Items Web Form Not Working

Nov 26, 2014

trying to enable database users to filter records based on column names which i have in a combobox. They enter the required value in a textbox and click the "Find" button.The code (linked to button click event) is not throwing any errors but the records are not being filtered.

View 4 Replies View Related

Forms :: Select Multiple Items By Pasting Comma Separated List

Apr 30, 2015

I have a list with 50 items in it, I would like to select some of these items by pasting in a coma separated list, is this possible?

View 12 Replies View Related

Tables :: Move Data From Listbox To Table

Aug 25, 2014

I have two listboxes on a form listbox1 and listbox2. listbox1 is populated by table1 which has 40 fields and 1000 records. listbox2 is populated by table2 which has identical structure to table1(same fields) but has no records.

For both listboxes Multi Select is set to simple. Rowsource is Select * statement from tables. Row Source Type is set to Table/Query.

I would like to select multiple records from listbox1 and add them to listbox2 and table2 or just table2. After selecting the records from listbox1 the user will click a button to add the records to table2. Also need to delete the values selected from table1 on same button click.

The database is saved with a .mdb file extension.

View 2 Replies View Related

Forms :: Task Storage Database - Form With Multiple Items And Submit Button

Oct 6, 2014

I have this database with the purpose to storage all the tasks that are done in my team. I have a table named Tasks with all their fields. Now, I would like to set a more user friendly way for clients to update this table. I have created another table with a list of most common tasks, so when a client wants to add their tasks list they can choose one of this tasks and add it to the list. I had created a form with multiple items that contains the common tasks and next to each task a button that adds the information they choose into the table "Tasks". This works just fine. However, I would like to add a single button at the top to add all the tasks instead of having to choose one after one.

The "Add All tasks" button has this code:

Private Sub Command79_Click()
Dim valSelect As Variant, MyDB As DAO.Database, MyRS As DAO.Recordset
Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecordset("Tasks", dbOpenDynaset)

[Code] ....

View 8 Replies View Related

Forms :: Change Backcolor Of A Field On Current Record Displayed In Multiple Items Form

Apr 8, 2013

I wish to change the backcolor of a field on a current record being dispalyed in a 'multiple items' form. However when using me.A.backcolor = makes refrence to all fields called A on the 'multiple items' form and therefore all fields change colour not just the current record.

View 2 Replies View Related

Select All Items In A Listbox

Sep 21, 2005

How to code a "Select all" button to a multi select listbox named lbSeleccionePuerto

View 2 Replies View Related

Select All Items Ina Listbox

Oct 11, 2006

Does anyone know if its possible to select all items (that is turn all items black) in a listbox? thanks

View 1 Replies View Related

Listbox: Disable Some Items

Dec 7, 2007

I have a list box bound to a table. 3 columns (ID, item, open). only item is visible. The box contains forms or reports that will open on double click. The column open contains the name of the form or report to open

Some forms and reports are a work in progress, hence, they are still listed in the list box but the open value is blank and of course won't run.

I'd like to change the colour of the list list box items that won't run.

I'm thinking maybe some kind of If.. isnull type statement...

any ideas are appreciated.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved