Results 1 to 9 of 9
  1. #1
    stildawn is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Oct 2013
    Posts
    185

    Change label caption based on listbox selection

    Hi All

    I have a listbox, with the record ID as the boundcolumn (and thus the listbox.value)

    I want to have a label caption to change to the "Notes" field value of the record selected in the listbox.



    I believe I do the code in a afterupdate on the listbox, but how do I use the ID number of a record (the listbox.value) to grab the value of that records "Notes" field?

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Check out the DLookup function

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Is Notes field a memo (long text) type?

    If not, try including Notes field as hidden column of listbox. Then expression in textbox references that column by index. If Notes is third column, index is 2:
    Code:
    =listboxname.Column(2)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    stildawn is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Oct 2013
    Posts
    185
    Yep just found it thanks.

    I have the code as:

    Code:
    Private Sub List8_AfterUpdate()
    
    NotesBody.Caption = DLookup("[Notes]", "FRT_Table", "[ID] =" & List8.Value)
    
    
    End Sub
    How this returns something like this: <div>ID 26 Test Notes</div>

    So its returning HTML tags etc, some other records also returns font colour tags etc as well, anyway to get rid of the tags?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    So I presume it is a memo type field set for Rich Text.

    Try: PlainText(DLookup("[Notes]", "FRT_Table", "[ID] =" & List8.Value))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    stildawn is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Oct 2013
    Posts
    185
    Yep thats it, I had it set to rich text.

    So I can simply change the field to Long Text - Plain Text and that solves it.

    But, is there a way I can achieve what I want while leaving as rich text? I used a label.caption because I dont want users of the form to be able to edit the notes at all, just view them. But is there another control type I could use that would enable rich text but not be able to be edited by the form user?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Textbox with the given expression in ControlSource.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    stildawn is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Oct 2013
    Posts
    185
    But can't users edit a textbox?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not when ControlSource is an expression. Try it. Let is know if you get different experience.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 01-06-2019, 01:51 PM
  2. Replies: 3
    Last Post: 11-20-2015, 11:06 AM
  3. Getting Value as label Caption
    By Naveen Marapaka in forum Forms
    Replies: 4
    Last Post: 09-18-2013, 12:22 AM
  4. Replies: 10
    Last Post: 06-18-2013, 02:00 PM
  5. Replies: 6
    Last Post: 01-16-2013, 12:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums