Ottiene il massimo valore di un campo
Funzione Visual Basic per ottenere il massimo valore da una tabella (o query) Access.
Public Function getMaxValue(table, neededField, whereCondition)
'legge un valore da una tabella db.
Dim myDb As Database
Set myDb = CurrentDb()
Dim sSql As String
Dim rsgetMaxValue As Recordset
sSql = " SELECT * FROM " & table
Set rsgetMaxValue = myDb.OpenRecordset(sSql)
If rsgetMaxValue.RecordCount = 0 Then
getMaxValue = 0
Else
rsgetMaxValue.Close
sSql = " SELECT '0'& MAX(" & neededField & ") AS MINIMO FROM " & table & " WHERE " & whereCondition
'MsgBox sSql
Set rsgetMaxValue = myDb.OpenRecordset(sSql)
getMaxValue = rsgetMaxValue("MINIMO")
End If
rsgetMaxValue.Close
Set rsgetMaxValue = Nothing
End Function
tags: vba visual basic macro access max massimo
I want to drink a coffee :-)