Results 1 to 2 of 2

Thread: access2k and datagrid control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Posts
    88
    using access 2000, i am trying to pass the results of a sql statement to a data grid control (or a flexgrid control if it is more convenient). from there, i want the user to be able to select the appropriate record which will then be displayed on the original form. unfortunately, i'm not quite sure how to get the data grid to display my results. does anyone have any suggestions?

  2. #2
    Lively Member Dr_Evil's Avatar
    Join Date
    Mar 2000
    Location
    Columbus, OH
    Posts
    105
    If you use the MSFlexGrid Control you could try something similar to the following.
    Code:
    Dim cnn As Connection
    Dim rs As Recordset
    Dim cmd1 As New ADODB.Command
    Dim str1 As String
    Dim fldLoop As ADODB.Field
        
        With cmd1
            .ActiveConnection = _
                "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=C:\\My Documents\Access Files\*.mdb;"
            .CommandText = "SELECT `*` FROM `TableName`"
            .CommandType = adCmdText
        End With
        
    'Run Query
        cmd1.Execute
        
    'Open Recorset on cmd1
        rs.Open cmd1
        
        Do Until rs.EOF
        
            str1 = ""
            For Each fldLoop In rs.Fields
                str1 = str1 & fldLoop.Value
            Next fldLoop
            MSFlexGrid1.AddItem str1
            rs.MoveNext
        Loop
        
        rs.Close
    Dr_Evil
    Senior Programmer
    VS6 EE
    VS.NET EA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width