?
Solved

Access VBA - edit line of a multicolumn Listbox

Posted on 2009-07-13
6
Medium Priority
?
1,567 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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 2000 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

770 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