CONSULTA COM PAGINA?ÃO

MARCIOR 10/02/2015 15:51:05
#444434
Como insiro na função abaixo o retorno de 10 registros por página por consulta :
[ô]rs.PageSize = 10

Public Function COnsulta_Seguros(ByVal PG As Integer) As Variant
Dim i As Integer
Set rs = CreateObject([Ô]ADODB.Recordset[Ô])
Dim erro As String
Dim lstItem As ListItem
[ô]Dim datt As Date
On Error GoTo erro

rs.Open [Ô]select Código, CodSegurado, NomeSegurado from TBSeguro[Ô], cn, adOpenKeyset, adLockOptimistic

With Form1.ListView4
.View = lvwReport
.GridLines = True
.FullRowSelect = True
.ListItems.Clear
.ColumnHeaders.Clear
End With

With Form1.ListView4.ColumnHeaders
.Add , , [Ô]Código :[Ô], 1000, lvwColumnLeft
.Add , , [Ô]CodSegurado:[Ô], 1000, lvwColumnLeft
.Add , , [Ô]NomeSegurado:[Ô], 2700, lvwColumnLeft

End With

rs.MoveFirst

Do Until rs.EOF
Set lstItem = Form1.ListView4.ListItems.Add(, , [Ô][Ô])
lstItem.Text = IIf(IsNull(rs!Código), [Ô][Ô], rs!Código)
lstItem.SubItems(1) = IIf(IsNull(rs!CodSegurado), [Ô][Ô], rs!CodSegurado)
lstItem.SubItems(2) = IIf(IsNull(rs!NomeSegurado), [Ô][Ô], rs!NomeSegurado)

rs.MoveNext


Loop
[ô]
rs.Close

ErrorHandlerExit:
Exit Function
ErrorHandler:
If Err = 3021 Then
Resume Next
ElseIf Err = 94 Then
Resume Next
ElseIf Err = 3420 Then
Resume Next
Else
MsgBox [Ô]Um erro inesperado Ocorreu![Ô] & _
Chr(13) & [Ô]Código do Erro : [Ô] & Err.Number & _
Chr(13) & [Ô]Descrição : [Ô] & Err.Description, vbCritical, [Ô]Erro do Sistema[Ô]
Resume ErrorHandlerExit
End If
erro:
End Function
MARCIOR 10/02/2015 23:32:55
#444446
Resolvido:
fonte:
http://vbknowcoding.greatknow.com/view/366738-ado-rs-close-or-set-nothing.html#


code:
[ô]set up the recordset, and load the data:

Dim rs as ADODB.Recordset

Set rs = New ADODB.Recordset

PageSize = 10

CacheSize = 10

Open [Ô]SELECT field1 FROM table1[Ô], cn, adOpenStatic, adLockReadOnly, adCmdText


[ô]use the data

Dim intRecord As Integer

If rs.EOF Then

Msgbox [Ô]No data found![Ô]

Else

[ô]for this example, go to the second page of data

AbsolutePage = 2

[ô]show the data for this page..

For intRecord = 1 To rs.PageSize

[ô]..do what we want with the data in this record

MsgBox rs.Fields([Ô]field1[Ô]).value


[ô]..move to the next record in this page

MoveNext

[ô]..if we have run out of records (which we may on the last page) exit the loop

If rs.EOF Then Exit For


Next intRecord

End If


[ô]tidy up

Close

Set rs = Nothing
Tópico encerrado , respostas não são mais permitidas