Solved

Access VBA - edit line of a multicolumn Listbox

Posted on 2009-07-13
6
1,357 Views
Last Modified: 2012-05-07
Hi. I add a line to a four column ListBox in Access using the following code
   oRowItem = s1 & ";" & s2 & ";" & s3 & ";" & s4  
    Me.lsbTasks.AddItem oRowItem
How would I edit the selected line in the listbox?
0
Comment
Question by:murbro
  • 3
  • 2
6 Comments
 
LVL 84
ID: 24842506
You can't edit anything directly in the listbox.

You could edit that line through VBA if you can locate it, however, you're probably better off just refilling the box with every record, with your edits in place.
0
 

Author Comment

by:murbro
ID: 24842569
Thanks. What VBA code would I use
0
 

Author Comment

by:murbro
ID: 24842580
If the user selects a line, surely I can use VBA code to edit that line
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 11

Expert Comment

by:datAdrenaline
ID: 24843847
>> If the user selects a line, surely I can use VBA code to edit that line <<

Not really ... you delete the row and add the row back ...

When the user selects a line in the list box, you would simply read the .ListIndex property then delete that line (item), create the item again, then add the item back.

Dim i As Long
i = listbox.ListIndex 'get the index of the item selected.
Me.lsbTasks.RemoveItem i
<code to set up the replacement line>
oRowItem = s1 & ";" & s2 & ";" & s3 & ";" & s4  
Me.lsbTasks.AddItem oRowItem, i

---------------------------

Do take note that .ListIndex is a 0 based number with 0 being the first item in the list ... UNLESS ... you have column headers turned on.  The column headers row actually consumes an item index value, and thus is ListIndex 0, if your have that option set.

Another method that may be of use to you is the .Column method ..

listbox.Column(ColumnIndex, RowIndex)

ColumnIndex is a number between 0 and the column count -1; RowIndex is the same as ListIndex above.
--------------------------------------------

As a side note, if you set the rowsource of your list box to a SQL statement, then you would modify the data, then .Requery the listbox or set the listboxes RowSource to itself (listbox.RowSource = listbox.RowSource).

Hope that helps!
0
 
LVL 11

Accepted Solution

by:
datAdrenaline earned 500 total points
ID: 24843897
Oh ... the .Column() method is used to return the value of a specific column/row.  Note that .Column will return a String, even if a number is shown in the ListBox.
0
 

Author Closing Comment

by:murbro
ID: 31602941
thanks very much
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now