|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Populating an MSFlexGrid
Hi, I am using a DAO connection to an Access database with VB 6.0. I have a DAO recordset of information that I have retrieved from the database using SQL. Now I want to populate a MSFlexGrid preferably *without* using bound controls. I currently only get the first field of the record and it shows up in the margin.
Here is what I have so far: Dim db As Database Dim ws As Workspace Dim Rst As DAO.Recordset Dim fld As Field Dim X As Integer Set ws = DBEngine.Workspaces(0) Set db = ws.OpenDatabase(MyConn) Set Rst = db.OpenRecordset("SELECT PatFirstName, PatLastName, PHN, Studydate FROM TBMAIN WHERE PHN LIKE '" & StrSearch & "*'", dbOpenSnapshot, dbReadOnly) If Rst.EOF Then MsgBox "No close matches found" Else For X = 1 To Rst.RecordCount frmGrid.MSFlexGrid1.AddItem Rst(X) Rst.MoveNext Next X Any ideas?
__________________
Best regards, Russ Bergen Senior Software Developer and Webmaster |
|
#2
|
||||
|
||||
|
build the string you want to add to the grid so that vbTabs seperate the values of the grid's columns, and then add the string using AddItem
|
|
#3
|
|||
|
|||
|
My old VB teacher e-mailed me this code. It works great. It uses the TextMatrix property:
Public Function PopulateFlexGrid(FlexGrid As Object, _ rs As Object) As Boolean On Error GoTo ErrorHandler If Not TypeOf FlexGrid Is MSFlexGrid Then Exit Function If Not TypeOf rs Is ADODB.Recordset Then Exit Function Dim i As Integer Dim J As Integer FlexGrid.FixedRows = 1 FlexGrid.FixedCols = 0 If Not rs.EOF Then FlexGrid.Rows = rs.RecordCount + 1 FlexGrid.Cols = rs.Fields.Count For i = 0 To rs.Fields.Count - 1 FlexGrid.TextMatrix(0, i) = rs.Fields(i).Name Next i = 1 Do While Not rs.EOF For J = 0 To rs.Fields.Count - 1 If Not IsNull(rs.Fields(J).Value) Then FlexGrid.TextMatrix(i, J) = _ rs.Fields(J).Value End If Next i = i + 1 rs.MoveNext Loop End If PopulateFlexGrid = True ErrorHandler: Exit Function End Function |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Populating an MSFlexGrid |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|