Results 1 to 8 of 8
  1. #1
    Join Date
    May 2011
    Posts
    47

    Unanswered: Altering the value in a ListBox

    I have a listbox that I want to change a value in by double clicking on a row in the list. I have two fields that I post from one listbox to another. I use the following code in the DblClickto event to change a "No" to "Yes" or "Yes" to "No".

    For Each i In Me.lst_add_accounts.ItemsSelected

    Me.txt_account.Value = Me.lst_add_accounts.Column(0, i)
    Me.txt_branded.Value = Me.lst_add_accounts.Column(1, i)

    If Me.txt_branded.Value = "No" Then

    Me.lst_add_accounts.Column(1, i) = "Yes"

    ElseIf Me.txt_branded.Value = "Yes" Then

    Me.lst_add_accounts.Column(1, i) = "No"

    End If

    Next i

    I keep getting a 424 error code: Object Required.

    I know I can AddItem or RemoveItem but there is no EditItem or anything like it that I can find.

    This seems like a simple issue but I can't seem to find a solution. Note, I do not want to go back to the database to accomplish this. I just want to make the change in the listbox for the user to see before it is saved to the database.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    The Column property of a list box (or of a combo box) is a read-only Variant (see Access help).
    Have a nice day!

  3. #3
    Join Date
    May 2011
    Posts
    47

    ListBox

    Thank you for your response. Does that mean that there is no way to alter the value in a list/combo box? My goal is to change the value.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    The Value property of a ListBox (or a ComboBox) is different from the contents of the list.
    For a Combo, the Value property (Read/Write) represents the contents of the TextBox part of the Combe (i.e. the part that's always visible and where you can type something). A ListBox does not have such a part, so it's value property is the value in its BoundColumn for the selected line (if a line is selected).

    In the code you posted you were trying to modify the contents of the list itself (.Column(x, y)), which cannot be done that way.
    Have a nice day!

  5. #5
    Join Date
    May 2011
    Posts
    47
    So, I guess the only way to do this is to save the information back to the database with a new value in the Yes/No field, and then reretrieve it?

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If the listbox is bound to a table, yes, that's the only way I can imagine. This can be done very quicly.
    Have a nice day!

  7. #7
    Join Date
    May 2011
    Posts
    47
    Okay, thanks. I've resorted to doing it that way.

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •