×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Microsoft Access - Using listbox to fill listbox

Microsoft Access - Using listbox to fill listbox

Microsoft Access - Using listbox to fill listbox

(OP)
HI this is my first post on this forum so bear with me. I have 2 tables "Albums" and "Songs". I am trying to create a form where I have 2 listboxes one for displaying albums and one for displaying songs. I want to be able to select an album from the "albums listbox" to bring up all the songs from that album in the "songs" listbox.

Im kinda confused with the logic aspect of it, and am completely lost on the coding part of it. Vb is confusing enough it seems to be even more confusing when you have tables and database objects in there as well.

Any help is much appreicated, thx.

RE: Microsoft Access - Using listbox to fill listbox

Make sure that each table has a keyfield (albumid, songid) and that you store the album keyfield in the songs table for a lookup.  (My keyfields are both Text fields.)

Set up 2 listboxes – one with records from albums and one from records in songs (drag listboxes onto your form and follow the wizard “I want records to look up a value in a table or query”)

(My albums listbox is List0 and my songs table listbox is List2)

Type the following VBA code into the After Update event of your albums table listbox, so that whenever you click an album, the songs for that album appear in the 2nd listbox.

Private Sub List0_AfterUpdate()
List2.RowSource = "select * from tblsongs where albumid = '" & List0 & "'"
List2.Requery
End Sub

(If your keyfields are autonumbers, you would need to have different punctuation in the 2nd line of the sub)

List2.RowSource = "select * from tblsongs where albumid = " & List0

Hope this helps - I can't work out how to put screen shots in here to help explain!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources