Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old July 23rd, 2003, 04:36 PM
utmostrusselb utmostrusselb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 40 utmostrusselb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #2  
Old July 31st, 2003, 07:41 AM
shafan's Avatar
shafan shafan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 123 shafan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 51 sec
Reputation Power: 6
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

Reply With Quote
  #3  
Old July 31st, 2003, 08:47 AM
utmostrusselb utmostrusselb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 40 utmostrusselb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Talking Answer:

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Populating an MSFlexGrid


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway