Wrox Programmer Forums
|
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 September 24th, 2006, 10:23 AM
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default ListBox--Displayyyyyyyyyyy

hello guyz i have not used Vb before in my life,I have coded using VC++ a lot,im having a problem displaying a result of a query as a table in a listboxxxxxx,however i am able to extraxt each field using record setssss,but i wanna display a table in a listbox--------IS THIS POSSIBLEEE-----or whts the best way to display a table on a FORM In VBA

 
Old September 24th, 2006, 10:38 AM
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can anybody help me on thissssssssssss or provide me the VB code for doing itttt

 
Old September 24th, 2006, 11:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Pass your recordset to a function that builds a semi-colon delimited string of all the values in your table, set you listbox's Row Source Type property to Value List and its Column Count property to the number of columns in your table. Then assign the string returned from your string building function to your ListBox's Rowsource property:

Code:
Private Sub cmdFillList_Click()
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strList As String
    Dim strSQL As String

    strSQL = "SELECT CategoryID, CategoryName FROM tblCategories " _
        & "ORDER BY CategoryName"

    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    rst.Open strSQL, cnn, adOpenStatic

    strList = BuildString(rst)
    lstListBox.RowSource = strList
    lstListBox.Selected(0) = True
    rst.Close
End Sub

Private Function BuildString(rst As ADODB.Recordset) As String
    Dim strReturn As String
    Dim varItems As Variant
    Dim x As Integer
    Dim y As Integer

    ' GetRows method returns a two-dimensional array
    With rst
        varItems = .GetRows(.RecordCount)
    End With

    For x = LBound(varItems, 2) To UBound(varItems, 2)
        For y = LBound(varItems, 1) To UBound(varItems, 1)
            strReturn = strReturn & varItems(y, x) & ";"
        Next y
    Next x
    BuildString = strReturn
End Function
HTH,

Bob

 
Old September 24th, 2006, 12:02 PM
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hey that surely helped and it works fine-----Fantastic logic --thanxxxx a lot BOB
i needed this one a lot to develop my tool --thanx againnnnnnn

 
Old September 24th, 2006, 12:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Yourrrrrrrr welcomeeeeeeeee mc. :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
ListBox obrienkev C# 2005 4 November 6th, 2007 03:15 AM
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
Listbox sarah lee ASP.NET 2.0 Basics 2 May 15th, 2007 02:09 PM
Help with listbox MMJiggy62 Beginning VB 6 5 July 11th, 2006 10:56 PM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM





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