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 :-)


Sponsored Links

voglio un Sito Web come questo - I want a Web Site like this

Ricerca


Ultimi Contenuti Inseriti

C# ASP.NET
...

How to add onload property to masterpage from child
HtmlGenericControl body = (HtmlGeneric...

SQL Server
...

Transpose Column to row
create table #temp (timeId int, dim1Id int, dim2I...

(X) HTML
Suggerimenti ed esempi riguardanti il linguaggio H...

Sponsor