Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 28th, 2005, 08:43 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to output records into list box with 3 coloum

Hi every one. i want out put records into a list box with 3 column headings named as playerno, initials and name. The way i created the list box is by putting list value for the row source type and name the list box as lstPlayers. But unfortunately get all the the records Fields one after one not one row at a time. I be happy if some one tell how to fix this .Thanks


Private Sub cmdSelect_Click()

  Dim cn As New ADODB.Connection
  Dim rst As New ADODB.Recordset
  cn.Open ("Provider=MicroSoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\db.mdb")

  rst.Open "select playerno, initials, name from players order by name, initials", cn
  rst.MoveFirst

  Do Until rst.EOF
    lstPlayers.RowSource = lstPlayers.RowSource & ";" & _
        rst("playerno") & ";" & rst("initials") & ";" & rst("name")

    rst.MoveNext
  Loop
  'TextBox = lstPlayers
   'MsgBox (playerno)
  rst.Close
  cn.Close
End Sub

 
Old April 29th, 2005, 07:40 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

check out the Properties on your list box... how many columns have you got? Sounds like 1 to me, change this to 3.

You will also maybe want to put a "; " at the start/end of each row?

I would suggest building your header string from the pre-populated contents of the rowsource and basically adding to it with your code, something like... (assuming your rst is already setup and called "rst")...

dim strRowSource as string
dim strLineItem as string

strRowsource = form!lstPlayers.RowSource
strLineItem = ""

do until rst.eof
 strlineitem = strlineitem & "; " & rst("playerno") & ";" & rst("initials") & ";" & rst("name")
 rst.moveNext
loop

strRowSource = strRowSource & strLineItem
forms!lstPlayers.RowSource = strRowSource



Putting the "; " at the start of the line and not the end means you won't get a "phantom" null after the last record.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.