Solved

Access VBA - edit line of a multicolumn Listbox

Posted on 2009-07-13
6
1,511 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:Murray Brown
[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 85
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:Murray Brown
ID: 24842569
Thanks. What VBA code would I use
0
 

Author Comment

by:Murray Brown
ID: 24842580
If the user selects a line, surely I can use VBA code to edit that line
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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:Murray Brown
ID: 31602941
thanks very much
0

Featured Post

MS Dynamics Made Instantly Simpler

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

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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