|
-
Apr 22nd, 2000, 08:47 PM
#1
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
-
Apr 24th, 2000, 03:25 AM
#2
Lively Member
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...
-
Apr 24th, 2000, 05:44 AM
#3
Addicted Member
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
-
Apr 24th, 2000, 07:05 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|