Copying values from a List Box into a Text Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Robertf987
    New Member
    • Feb 2007
    • 23

    #1

    Copying values from a List Box into a Text Box

    Hello,
    I am creating a database in Microsoft Access 2000. It's to store books and other resources, like a library database (just to give you a bit of a background). I have a field called "Subject". It's a text field. In there, you manually type in the subject(s) that that book relates to, for example Sports, Health, Sex Education, Careers, Citizenship, etc. However, it's a bit inefficient to have to manually type in these words.

    However, I would like to arrange this so the subjects don't have to be typed in. I would like to have a list box on the form with all the subjects listed in it. Then when you click a subject in the list box, it will copy it into the 'subject' field. More than one subject needs to be selectable, sor example you may have a book that relates to... sex education and health and wellbeing, so I may want all three subjects to be copied into the subject field.

    I want to keep the subject field as a text box, I only want the words from the list box copied and pasted into the subject field (preferably seperated by commas). (i.e. If I select Health and Drugs in the List Box I want to create, I want "Health, Drugs" to appear in the existing 'Subject' text box.

    Hope somebody can help. If somebody does reply, please can you talk nice and s-l-o-w-l-y for me, I have a stinking cold and through my eyes watering I can barely see my monitor, let alone comprehend anything remotely complex! The answer may be simple, I have a feeling I may have some something simmilar in college before. But I can't find anything and I've searched the net and can't find an answer. I'd very much appreciate any help anybody can give.

    Thanks, Robert.
  • Robertf987
    New Member
    • Feb 2007
    • 23

    #2
    I'm actually replying to my own question, I found an old database with what I needed in it. I thought I'd put the answer on here just incase anybody else was searching for it.

    I put the following code into the on click procedure for the list box:
    Code:
    If Len(Nz(Me!Subject.Value)) > 0 Then
        Me!Subject.Value = Me!Subject.Value & ", " & Me!List13.Value
    Else
        Me!Subject.Value = Me!List13.Value
    End If
    This code copies the value selected in the list box into the text box, and if more than one is selected, they are seperated by commas.

    Comment

    Working...