Solved

Access VBA - edit line of a multicolumn Listbox

Posted on 2009-07-13
6
1,460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

730 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