|
|
|
|
|
Dicas
|
|
Visual Basic (ActiveX/Controles/DLL)
|
|
|
Título da Dica: Pegar o último registro( SELECT MAX)
|
|
|
|
Postada em 27/6/2007 por Jailton Sampaio
jailton_sampaio@hotmail.com
Public Function MaxRecord(pStrTable As String, pStrCampo As String, Optional pStrFiltro As String) As Long Dim lRstMax As ADODB.Recordset Dim lStrQuery As String Set lRstMax = New ADODB.Recordset lStrQuery = "SELECT Max(" & pStrCampo & ") FROM " & pStrTable
If Trim(pStrFiltro) <> "" Then lStrQuery = lStrQuery & " WHERE " & pStrFiltro End If lRstMax.Open lStrQuery, gConnSiem, adOpenStatic, adLockReadOnly If lRstMax.EOF Then MaxRecord = 1 Else MaxRecord = IIf(IsNull(lRstMax(0).Value), 0, lRstMax(0).Value) + 1 End If lRstMax.Close Set lRstMax = Nothing
End Function
|
|
|
|
|