I am trying to use the DataList control, I would like to display two fields from my database in the List. I can get one field to show but how do I display more than one field from my database.<br><br>
This is what I came up with for now!<br><br>First I run the Load_List() function in the Form Load. This will load the first and second fields from the Adodc1.<br>I load the key field from the table into the list1.ItemData so any time I select an Item from the list it then runs a do loop to move the adodc1 recordset to the record with the same key value.<br><br><br><br>-----------------------------------------------------<br>Function Load_List()<br> Adodc1.Recordset.Update<br> Adodc1.Recordset.MoveFirst<br> List1.Clear<br> Do While Not Adodc1.Recordset.EOF<br> List1.AddItem Adodc1.Recordset(1) & "." & Adodc1.Recordset(2)<br> List1.ItemData(List1.NewIndex) = Adodc1.Recordset(0)<br> Adodc1.Recordset.MoveNext<br> Loop<br> <br> Adodc1.Recordset.MoveFirst<br>End Function<br>----------------------------------------------------<br><br>Private Sub List1_Click()<br> On Error GoTo ErrorList1<br><br> <br> Do While (List1.ItemData(List1.ListIndex) <> Adodc1.Recordset(0))<br> Adodc1.Recordset.MoveNext<br> Loop<br> <br>ErrorList1:<br>Adodc1.Recordset.MoveFirst<br> Do While (List1.ItemData(List1.ListIndex) <> Adodc1.Recordset(0))<br> Adodc1.Recordset.MoveNext<br> Loop<br> <br>End Sub<br><br>----------------------------------------------------<br><br>That's the best I can do for now, until I find a better solution. If anybody has any suggestions let me know.<br><br>p.s. Dont be a SUB be a Function!
Leaf,<br><br>Instead of that wee loop you *could* use the Recordset.FindFirst method.<br><br><FONT FACE=monospace><b><br>Adodc1.Recordset.MoveFirst<br>Adodc1.Recordset.FindFirst "fld0 = " & (List1.ItemData(List1.ListIndex) <br></font></b><br><br>Doesn't matter with small datasets but might make quite a difference with the larger ones. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href=
Cargill's Corporate Web Site</a><br>Please -- Don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.