Content of text box to depend on selected value in list box?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a list box displaying one column (Names) from my database. When I
select one entry in this list box, I want information from other rows to be
displayed in text boxes (Title, Description, etc.) in the same form. I've
read around, and I know this involves an AfterUpdate event, but I don't know
what code to use, nor what the Control Sources should be for my text boxes
(if indeed this is the right path to follow). You can assume I know nothing
about coding and requiries and the like.

Many thanks for any help you may offer.

~Maruno
 
Maruno,

Don't worry too much about control sources. Just push the values from the
listbox to the textboxes.

Assuming the listbox columns are title, description and somethingelse (in
that order):
Private Sub lstMyListBox_Click()
If Not IsNull(Me!lstMyListBox) Then
Me!txtTitle = Me!lstMyListBox.Column(0)
Me!txtDescription = Me!lstMyListBox.Column(2)
Me!txtSomethingElse = Me!lstMyListBox.Column(3)
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
 
That's almost solved it. That's great.

However, when I try to choose which column to display in the text boxes, I
can only properly choose columns 0, 1 and 2. Columns 3 and 4, which I need,
do not display anything. I cannot find anything different between the text
boxes, nor between columns 0, 1 & 2, and 3 & 4. The text box remains blank,
and there is no error message. The text boxes all display properly when I set
it to show columns 0, 1 or 2.


~Maruno
 
Maruno said:
That's almost solved it. That's great.

However, when I try to choose which column to display in the text boxes, I
can only properly choose columns 0, 1 and 2. Columns 3 and 4, which I need,
do not display anything. I cannot find anything different between the text
boxes, nor between columns 0, 1 & 2, and 3 & 4. The text box remains blank,
and there is no error message. The text boxes all display properly when I set
it to show columns 0, 1 or 2.

Make sure that you have that many columns in your list box. Graham's
sample code showed you 3 columns, but you need to make sure that the
recordsource of the listbox has the additional information in it for you
to reference it (even if it's column width is 0" and effectively hidden)
 
Yes, I just figured that out myself. I'd only referenced the ID and the title
in the list, when I should have referenced my whole table (and set the column
widths to zero).

Thank you very much for your help. Problem solved!


~Maruno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top