Ottiene il minimo valore di un campo

Funzione Visual Basic per ottenere il minimo valore da una tabella (o query) Access.




Public Function getMinValue(table, neededField, whereCondition)
'legge un valore da una tabella db.
  Dim myDb As Database
  Set myDb = CurrentDb()
  Dim sSql As String
  Dim rsgetMinValue As Recordset

  sSql = " SELECT * FROM " & table
  Set rsgetMinValue = myDb.OpenRecordset(sSql)

  If rsgetMinValue.RecordCount = 0 Then
    getMinValue = 0
  Else
    rsgetMinValue.Close
    sSql = " SELECT '0'& MIN(" & neededField & ") AS MINIMO FROM " & table & " WHERE " & whereCondition
    'MsgBox sSql
    Set rsgetMinValue = myDb.OpenRecordset(sSql)
    getMinValue = rsgetMinValue("MINIMO")
  End If

  rsgetMinValue.Close
  Set rsgetMinValue = Nothing
End Function


tags: vba visual basic macro access min minimo

I want to drink a coffee :-)


Sponsored Links

google logo
Google Search di LifeInRete.it


Inserisci nel tuo sito il modulo di ricerca Google di LifeInRete.it! Copia il seguente modulo:

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