Hi
I am trying to display a table from Access in a Flexgrid.

For some reason, the flexgrid only displays the first record from the table and doesnot show any other record!
Can someone please help!!

Here's the code:

Set cmd.ActiveConnection = conn

cmd.CommandText = "SELECT WFJob,JobTitle,FLSA FROM Delte where WFTJob= '" & str & "'"
cmd.CommandType = adCmdText
Set rs = cmd.Execute


frmReport.MSGrid1.Cols = rs.Fields.Count + 1
HSE = 1

frmReport.MSGrid1.Row = 0
frmReport.MSGrid1.Col = 0

For j = 0 To rs.Fields.Count - 1
frmReport.MSGrid1.Col = j + 1
frmReport.MSGrid1.Text = rs.Fields(j).Name
Next


If rs.EOF = False Then

'Assigning Column names to flexgrid 1st row

Do While Not rs.EOF
frmReport.MSGrid1.Row = HSE
frmReport.MSGrid1.Col = 0
frmReport.MSGrid1.Text = HSE
For j = 0 To rs.Fields.Count - 1
frmReport.MSGrid1.Col = j + 1
frmReport.MSGrid1.Text = IIf(IsNull(rs(j)), "", rs(j))

Next j
rs.MoveNext
DoEvents

HSE = HSE + 1
Loop
End If

Next i

frmReport.Show

Thanks in advance for your help!!

Recommended Answers

All 3 Replies

Hi,
You did not specify number of rows for flex grid
Add

frmReport.MSGrid1.Rows = rs.RecordCount + 1

before

frmReport.MSGrid1.Cols = rs.Fields.Count + 1

Hi,

Change your "Do--Loop" code to:

Do While Not rs.EOF
   For j = 0 To rs.Fields.Count - 1
      frmReport.MSGrid1.TextMatrix(HSE,j) =IIf(IsNull(rs(j)), "", rs(j))
   Next j
   rs.MoveNext
   HSE = HSE + 1
Loop

Regards
Veena

Hi,

Change your "Do--Loop" code to:

Do While Not rs.EOF
   For j = 0 To rs.Fields.Count - 1
      frmReport.MSGrid1.TextMatrix(HSE,j) =IIf(IsNull(rs(j)), "", rs(j))
   Next j
   rs.MoveNext
   HSE = HSE + 1
Loop

Regards
Veena

Thanks for your reply...
That didnot seem to fix the problem
The problem seems to be with my list box where I am converting the selections to a string, only fisrt selection gets displayed. It doesnot display the records corresponding to the rest of the selections in the list box.


Here's the complete code.

Private Sub cmdReport_Click()
Dim str As String
Dim i As Integer
Dim j As Integer


If lstCode.ListIndex = -1 Then Exit Sub


Set cmd.ActiveConnection = conn

For j = lstCode.ListCount - 1 To 0 Step -1
str = lstCode.List(j)
cmd.CommandText = "SELECT * FROM HSE where WFTJob = '" & str & "'"
cmd.CommandType = adCmdText
Set rs = cmd.Execute
Next j

frmReport.MSGrid1.Cols = rs.Fields.Count + 1
sno = 1

frmReport.MSGrid1.Row = 0
frmReport.MSGrid1.Col = 0
frmReport.MSGrid1.Text = ""
For i = 0 To rs.Fields.Count - 1
frmReport.MSGrid1.Col = i + 1
frmReport.MSGrid1.Text = rs.Fields(i).Name
Next


If rs.EOF = False Then

'Assigning Column names to flexgrid 1st row

Do While Not rs.EOF
frmReport.MSGrid1.Row = 1
frmReport.MSGrid1.Col = 0
frmReport.MSGrid1.Text = sno


For i = 0 To rs.Fields.Count - 1
frmReport.MSGrid1.Col = i + 1
frmReport.MSGrid1.Text = IIf(IsNull(rs(i)), "", rs(i))
Next
sno = sno + 1
DoEvents
rs.MoveNext
Loop
End If


frmReport.Show

End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.