Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need link data from Access in datacombo,datalist

Status
Not open for further replies.

JanClutch

Programmer
Dec 24, 2000
1
ZA
I am useing a Access data base. I need to display a list of product makes in a combo box. Through the click event I need to display the models for a make in a list box and a picture for each model when it is clicked.
 
Hi

To do this painlessly you'd have to have a corectly designed db. I'll assume you have.

i.e.

Make Table
1) Make ID [Unique]

Model Table
1) Make ID [This relates to the Make Table]

You can either load the models dynamically or before hand depending on the amount of data, your programming preferences & program design.
'First Load your Combo Box from the "Make Table"

Private Sub ms_LoadCombo()
'Code to open db & table goes here
'....
Combo1.Additem MakeDescriptionGoesHere
Combo1.ItemData(Combo1.NewIndex) = MakeIDGoesHere
'....
End Sub
Code:
Private Sub Combo1_Click()

   With Combo1
      ms_LoadModel(.ItemData(.ListIndex))
   End With

End Sub
Here's the ms_LoadModel Procedure
Code:
Private Sub ms_LoadModel(iMakeID As Integer)

   'iMakeID = the Id that's found in the Model Table that
   'relates to the Id found in the Make table. ;-) "phew"

   'Open Model Table Where MakeId = iMakeID
   'Loop through returned records (if any) 
   'and add to listbox
   ListBox1.AddItem
ModelDescriptionGoesHere
Code:
End Sub

'Now you probably have the picture in the Model Table as well. I don't know if you're going to store the picture itself in the databse or just a link to the picture eg
"c:\SomeDir\SomeModel.jpg"

To store the link takes up less space & uses less code to implement. It does have drawbacks in that the pictures are separate from the data & you have to worry about cataloguing the pics a number of other restrictions lie in this design as well which I will not explore at this time.

The other approach would be to store the pics itself in the db. This can slow down your data access in many ways since it takes more code to show the picture from the db & or store the picture in a db.

Let me know which approach you'll be taking & I'll send the appropriate code.

Seasons Greetings
caf

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top