Click to See Complete Forum and Search --> : Msflexgrid - recordset
DonRafouk
March 14th, 2001, 09:18 PM
'Type mismatch' error occur when I put in codes below ....
SQLStr= "SELECT CUSTOMERID FROM TABLE 1"
MSFlexGrid1.Datasource = SQLStr
how do I rewrite the codes ?????
thank you
DonRafouk
Iouri
March 15th, 2001, 07:19 AM
I think that the better way of doing it - is to create a recordset using your SQL and then enter recordset to MSFlexGrid
If you use an MSFlexGrid control to display data returned in an ADO recordset, you can use this code to
dynamically populate the grid-including the header row-with the information in the recordset. You need an
open ADO recordset named rst and a form containing an MSFlexGrid control named msfGrid:
Dim cln As Field
With msfGrid
.Rows = 2
.Cols = rst.Fields.Count
'get the number of grid cols
.FixedRows = 1
.FixedCols = 0
.Row = 0
.Col = 0
For Each cln In rst.Fields
.Text = cln.Name
'populate header row with names of fields
If .Col < .Cols - 1 Then .Col = .Col + 1
Next
Do While Not rst.EOF
'loop thru recordset to populate grid
.Row = rst.AbsolutePosition
'move to the next row
.Col = 0
'reset ourselves back to column(0)
For Each cln In rst.Fields
If Not IsNull(cln.Value) Then
.Text = Trim(CStr(cln.Value))
Else
.Text = ""
End If
If .Col < .Cols - 1 Then .Col = .Col + 1
Next
rst.MoveNext
.Rows = .Rows + 1
'add a new row to the grid
Loop
.Rows = .Rows - 1
'remove the last row because it's blank
.Row = 0
End With
Iouri Boutchkine
iouri@hotsheet.com
Iouri
March 15th, 2001, 07:22 AM
Another way of doing this
ADC - is your recordset
ADC.Open SQL, Connection.......
MSFlexGrid1.Cols = ADC.Fields.Count + 1
Dim V
Do While Not ADC.EOF
V = V + 1
ADC.MoveNext
Loop
ADC.MoveFirst
MSFlexGrid1.Rows = V + 1
MSFlexGrid1.Row = 0
MSFlexGrid1.Col = 1
ADC.MoveFirst
Dim MyResource
MyResource = ADC.GetString
MsFlexGrid1.Cols = ADC.Fields.Count
For X = 0 To ADC.Fields.Count - 1
MSFlexGrid1.TextMatrix(0, X) = ADC.Fields(X).Name
Next
MSFLEXGRID1.Row = 1
MSFLEXGRID1.Col = 0
MSFLEXGRID1.RowSel = MSFLEXGRID1.Rows - 1
MSFLEXGRID1.ColSel = MSFLEXGRID1.Cols - 1
MSFLEXGRID1.Clip = MyResource
MSFLEXGRID1.RowSel = MSFLEXGRID1.Row
MSFLEXGRID1.ColSel = MSFLEXGRID1.Col
End Sub
Iouri Boutchkine
iouri@hotsheet.com
DonRafouk
March 15th, 2001, 10:09 PM
Thanks to you Iouri , I think I've got the Idea already.
Thanks a lot.
DonRafouk
Iouri
March 16th, 2001, 07:10 AM
Rate it if it helped you
Iouri Boutchkine
iouri@hotsheet.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.