1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
Function Calcul_Cs(Optional ByVal Diametre_vis As Double, _
Optional ByVal Classe As String, _
Optional ByVal Coef_Frottement As Double) As Integer
' Double 1 : Diametre de la vis
' String : Classe de la vis
' Double 2: Coefficient de frottement du montage
Dim rec As New ADODB.Recordset
Dim strSQL As String
'Redaction du SQL
strSQL = "SELECT Serrage.Cs" & _
"FROM Vis INNER JOIN (Frottement INNER JOIN (Classe INNER JOIN Serrage ON Classe.Classe = Serrage.CorresClasse) ON Frottement.[Coefficient de frottement] = Serrage.CorresFrot) ON Vis.[Diametre (mm)] = Serrage.CorresDia WHERE 1=1"
'Insertion de la variables de recherche "Diametre"
If Diametre_vis > 0 Then
strSQL = strSQL & " And ([Vis]![Diametre (mm)] = " & Diametre_vis & ")"
End If
' Insertion de la variables de recherche "Classe"
If Len(Classe) > 0 Then
strSQL = strSQL & " And ([Classe]![Classe] ='" & Classe & "')"
'End If
'Insertion de la variables de recherche "Coefficient de frottement"
If Coef_Frottement > 0 Then
strSQL = strSQL & " And ([Frottement]![Coefficient de frottement] = " & Coef_Frottement & ")"
End If
Dim rst As New ADODB.Recordset
rst.Open strSQL, cnx
rst.MoveFirst
Calcul_Cs = CDbl(rst("Cs"))
rst.Close
Set rst = Nothing
End Function |
Partager