Public Function DLookup(Pole As String, Tabela As String, Optional ByVal Uslov = "") As Variant
On Error Resume Next
Dim rsdl As ADODB.Recordset
Dim StrSQL As String
If IsNull(Uslov) Or Uslov = "" Then
StrSQL = "SELECT " & Tabela & "." & Pole & " FROM " & Tabela
Else
StrSQL = "SELECT " & Tabela & "." & Pole & " FROM " & Tabela & " WHERE ((" & Tabela & "." & Uslov & "))"
End If
Set rsdl = cn.Execute(StrSQL)
If Not (rsdl.EOF And rsdl.BOF) Then
rsdl.MoveFirst
'DLookup = rsdl(Pole).Value
DLookup = rsdl(0).Value
Else
DLookup = ""
End If
End Function
Public Function DCount(ByVal Pole As String, ByVal Tabela As String, Optional ByVal Uslov = "")
Dim rsdc As ADODB.Recordset
Dim StrSQL As String
Dim I As Integer
I = 0
If IsNull(Uslov) Or Uslov = "" Then
StrSQL = "SELECT " & Tabela & "." & Pole & " FROM " & Tabela
Else
StrSQL = "SELECT " & Tabela & "." & Pole & " FROM " & Tabela & " WHERE ((" & Tabela & "." & Uslov & "))"
End If
Set rsdc = cn.Execute(StrSQL)
If Not (rsdc.EOF And rsdc.BOF) Then
rsdc.MoveFirst
Do While Not rsdc.EOF
I = I + 1
rsdc.MoveNext
If rsdc.EOF Then
Exit Do
End If
Loop
DCount = I
Exit Function
Else
DCount = ""
Exit Function
End If
End Function
Public Function DMax(ByVal Pole As String, ByVal Tabela As String, Optional ByVal Uslov = "")
' On Error Resume Next
Dim rcMax As Recordset
Dim strMax As String
If IsNull(Uslov) Or Uslov = "" Then
strMax = "SELECT Max(" & Tabela & "." & Pole & ") AS MaxVrednost " & " FROM " & Tabela & ""
Else
strMax = "SELECT Max(" & Tabela & "." & Pole & ") AS MaxVrednost " & " FROM " & Tabela & " WHERE (" & Tabela & "." & Uslov & ")"
End If
Set rcMax = cn.Execute(strMax)
If IsNull(rcMax!MaxVrednost) Then
DMax = ""
Else
DMax = rcMax!MaxVrednost
End If
rcMax.Close
End Function
Public Function DMin(ByVal Pole As String, ByVal Tabela As String, Optional ByVal Uslov = "")
Dim rcMin As ADODB.Recordset
Dim strMin As String
If IsNull(Uslov) Or Uslov = "" Then
strMin = "SELECT Min(" & Tabela & "." & Pole & ") AS MinVrednost " & " FROM " & Tabela & ""
Else
strMin = "SELECT Min(" & Tabela & "." & Pole & ") AS MinVrednost " & " FROM " & Tabela & " WHERE (" & Tabela & "." & Uslov & ")"
End If
Set rcMin = cn.Execute(strMin)
If IsNull(DMin = rcMin!MinVrednost) Then
DMin = ""
Else
DMin = rcMin!MinVrednost
End If
rcMin.Close
End Function