Set BancoDeDados = OpenDatabase(App.Path & "olão.MDB", False)
Set TBSaldo = BancoDeDados.OpenRecordset("select Matricula,Nome,Saldo from Saldo Where Data >= #" & Format(DataInicial, "mm/dd/yy") & "# and data<= #" & Format(DataFinal, "mm/dd/yy") & "# order by Saldo asc")
If Not TBSaldo.EOF Then
With MSFlexGrid1
.Rows = 1
.Cols = 4
.ColWidth(0) = 500
.ColWidth(1) = 800
.ColWidth(2) = 3000
.ColWidth(3) = 700
.TextMatrix(0, 0) = "Lugar"
.TextMatrix(0, 1) = "Matricula"
.TextMatrix(0, 2) = "Nome"
.TextMatrix(0, 3) = "Valor"
End With
i = 1
Do While Not TBSaldo.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) = TBSaldo(0)
.ColAlignment(2) = flexAlignLeftCenter
.TextMatrix(i, 2) = TBSaldo(1)
.ColAlignment(3) = flexAlignCenterCenter
.TextMatrix(i, 3) = TBSaldo(2)
End With
i = i + 1
SomaColuna = SomaColuna + TBSaldo(2)
TBSaldo.MoveNext
Loop
' Textbox com o total da coluna
Text1.Text = SomaColuna
Ou :
Dim i As Integer
Dim aux As Double
For i = 1 To MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Row = i
MSHFlexGrid1.Col = 1 'coluna que vc quer somar
aux = aux + MSHFlexGrid1.Text
label1.Caption = aux 'local onde vc quer exibir a soma
Next