Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsFlexGrid showing one less record 1

Status
Not open for further replies.

homesick

Programmer
Dec 5, 2001
55
CA
I have a Flexgrid but it always shows 1 less record. If i have 6 records for one Agent, it shows 1 record with no name, and then it shows 5 records with the correct name.
Am i making sense?
Here is my code


Private Sub Combo5_Change()
Dim db As Database
Dim rs As Recordset

Dim strFile As String
Dim strSQL As String

strFile = "a:\tracker"
strSQL = "SELECT * FROM tracker WHERE aname = '" & Combo5.Text & "'"

Set db = OpenDatabase(strFile)
Set rs = db.OpenRecordset(strSQL)

Call DisplayRSGrid(rs, MSFlexGrid1)

rs.Close
db.Close

Set rs = Nothing
Set db = Nothing

If MSFlexGrid1.Rows - 1 = 1 Then
MsgBox MSFlexGrid1.Rows - 1 & " record.", vbInformation, Me.Caption
Else
MsgBox MSFlexGrid1.Rows - 1 & " records.", vbInformation, Me.Caption
End If

End Sub
 
Pasted wrong code...here it is....


Public Function DisplayRSGrid(rs As DAO.Recordset, grid As MSFlexGrid, Optional Form As Form)

Dim fld As DAO.Field

On Error Resume Next

Screen.MousePointer = vbHourglass

With grid

.Redraw = False

'Setup the grid
.Cols = rs.Fields.Count
.Rows = 1
.Row = 0
.Col = 0
MSFlexGrid1.ColWidth(0) = 2000
MSFlexGrid1.ColWidth(1) = 2000
MSFlexGrid1.ColWidth(3) = 1000
MSFlexGrid1.ColWidth(4) = 2000
MSFlexGrid1.ColWidth(5) = 600
MSFlexGrid1.ColWidth(6) = 600
MSFlexGrid1.ColWidth(7) = 600
MSFlexGrid1.ColWidth(9) = 600
MSFlexGrid1.ColWidth(12) = 600
MSFlexGrid1.ColWidth(13) = 600
MSFlexGrid1.ColWidth(14) = 800
rs.MoveFirst

'Setup the grid headings
For Each fld In rs.Fields
.Col = fld.OrdinalPosition
.ColWidth(.Col) = Form.TextWidth(String(fld.Size + 9, "a")) '.Width/ rs.Fields.Count
.Text = fld.Name
Next fld

'Move through each row in the recordset.
Do Until rs.EOF
.Rows = grid.Rows + 1
.Row = .Rows - 1

'Loop through all fields.
For Each fld In rs.Fields
.Col = fld.OrdinalPosition
.Text = fld.Value
Next fld

rs.MoveNext

Loop

.Redraw = True

End With

Screen.MousePointer = vbNormal

End Function
 
Try:

While Not rs.EOF
.Rows = grid.Rows + 1
.Row = .Rows - 1

'Loop through all fields.
For Each fld In rs.Fields
.Col = fld.OrdinalPosition
.Text = fld.Value
Next fld
rs.MoveNext

Wend


Mark
 
Mark:

Sorry to sound stupid but where i my code do i place this?
 
Mark:

Sorry to sound stupid but where in my code do i place this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top