Segue mais um exemplo:
Private Sub Usuario_Click()
On Error GoTo Trata_Erro
Me.MousePointer = 11
Set BancoDeDados = OpenDatabase(App.Path & "salao.MDB", False)
Set TBDados = BancoDeDados.OpenRecordset("select Data,Nome,comentario,sum (valor) from dados Where Data >= #" & Format(DataInicial, "mm/dd/yy") & "# and data<= #" & Format(DataFinal, "mm/dd/yy") & "# and Usuario='" & Nomeusuario.Text & "' group by Data,Nome,comentario order by data desc")
If Not TBDados.EOF Then
With MSFlexGrid1
.Rows = 1
.Cols = 5
.ColWidth(0) = 0
.ColWidth(1) = 1000
.ColWidth(2) = 3300
.ColWidth(3) = 0
.ColWidth(4) = 1200
.MergeCells = flexMergeFree
.MergeCol(1) = True
.TextMatrix(0, 0) = ""
.TextMatrix(0, 1) = "Data"
.TextMatrix(0, 2) = "Cliente"
.TextMatrix(0, 3) = ""
.TextMatrix(0, 4) = "Valor"
End With
i = 1
Do While Not TBDados.EOF
With MSFlexGrid1
.Rows = i + 1
.ColAlignment(0) = flexAlignCenterCenter ' alinha coluna
.TextMatrix(i, 0) = i - 0 ' autonumeração colocar zero para poder começar com 1
.ColAlignment(1) = flexAlignCenterCenter
.TextMatrix(i, 1) = TBDados(0)
.ColAlignment(2) = flexAlignLeftCenter
.TextMatrix(i, 2) = TBDados(1)
.ColAlignment(3) = flexAlignLeftCenter
.TextMatrix(i, 3) = TBDados(2)
.ColAlignment(4) = flexAlignRightCenter
.TextMatrix(i, 4) = Format(TBDados(3), "Currency")
.Col = 4
.Row = i
.CellForeColor = vbRed
.CellFontBold = True
End With
i = i + 1
SomaColuna = SomaColuna + TBDados(3)
TBDados.MoveNext
Loop
' Textbox com o total da coluna
Saldo.Text = Format(SomaColuna, "currency")
End If
FlexCores &HFFFFFF, &HC0FFFF ' função para deixar com efeito zebrado
Me.MousePointer = 0
Exit Sub
Trata_Erro:
MsgBox "Você Selecionou DADOS INVÁLIDOS!!!!"
end sub
Abaixo a função para deixar zebrado:
Sub FlexCores(lCorPar As Long, lCorImpar As Long)
Dim iLinha As Integer
MSFlexGrid1.FillStyle = flexFillRepeat
For iLinha = 1 To MSFlexGrid1.Rows - 1
With MSFlexGrid1
.Row = iLinha
If EImpar(iLinha) Then 'Se a linha for impar:
'Seleciona a partir da primeira coluna
.Col = 1
'Seleciona até a última coluna
.ColSel = .Cols - 1
'Aplica a cor
.CellBackColor = lCorImpar
Else 'Se a linha for par:
'Seleciona a partir da primeira coluna
.Col = 1
'Seleciona até a última coluna
.ColSel = .Cols - 1
'Aplica a cor
.CellBackColor = lCorPar
End If
End With
Next
MSFlexGrid1.FillStyle = flexFillSingle
End Sub