Results 1 to 4 of 4

Thread: Populate DBGrid without using a data control is this possible

  1. #1
    Guest

    Question

    Ive tried to populate a DBGrid control without using a data control object without success heres some things I tried

    Set dbgOrderMaster.DataSource = MR_OS.grstCurrentRS
    Set dbgOrderMaster.RecordSource = MR_OS.grstCurrentRS

    The recordset MR_OS.grstCurrentRS works fine Ive used it to set some text boxes

  2. #2
    Lively Member Dr_Evil's Avatar
    Join Date
    Mar 2000
    Location
    Columbus, OH
    Posts
    105
    Yes it is possible to populate your dbGrid with out using a data control. I prefer to use an ADO connection (Coded not the control) toconnect to the database. From there I use SQL to select the desired fields.
    Code:
    'Query by Chemical Name
    Sub cmdQueryChemical_Click()
    
        Dim cnnLabTracking As New Connection
        Dim rsChemicalName As Recordset
        Dim cmd1 As Command
        Dim str1 As String
        Dim fldLoop As ADODB.Field
        
    
        Set cmd1 = New ADODB.Command
    
        With cmd1
            .ActiveConnection = _
                "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=C:\My Documents\Access Files\Lab Tracking.mdb;"
            .CommandText = "SELECT SampleNumber, `Chemical Name`, `Container Number`, `Container Weight`," & _
            "`Description`, `Part Number`, `Batch`, `Screener`, `Department`, `Operator`," & _
            "`Date` " & _
            "FROM SampleLogin " & _
            .CommandType = adCmdText
        End With
       
        
        'Run query.
            cmd1.Execute
        'Clear data grid
            vfgSearchResults.Clear
        
        'Open recordset on cmd1 
            Set rsChemicalName = New ADODB.Recordset
            rsChemicalName.Open cmd1
        
        Do Until rsChemicalName.EOF
        vfgSearchResults.AddItem str1, 0
            str1 = ""
            For Each fldLoop In rsChemicalName.Fields
                str1 = str1 & fldLoop.Value & Chr(9)
            Next fldLoop
            vfgSearchResults.Refresh
            Debug.Print str1
            rsChemicalName.MoveNext
        Loop
    
        rsChemicalName.Close
        
    End Sub
    This is just a quick example & may not be exact. It's quitting time now. If you need more help just post & I'll reply asap...

  3. #3
    Addicted Member pardede's Avatar
    Join Date
    Jan 2000
    Posts
    232
    If you're using VB6 with ADO you can indeed use a recordset object to fill DBGrid without using data control:

    Set DBGrid1.DataSource = YourDB.rsYourRecordset

  4. #4
    Guest

    Thumbs up Thanks Ill try that

    Thanks guys. I have MDAC 2.0 and am using data grid 5.0 (sp3)
    can only certain grid versions do this?

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