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 41 42 43 44 45 46 47 48
| Function RechercheDouleOption(DesigneTable As String, CodeTable As String, LibTable As String) As Boolean
'cette fonction permet de faire la recherche locale au niveau des formulaires de camion,destination,et de region,et article
'elle prend en argument la désignation de la table,les désignations des champs code ,nom et prénom de ladite table
Dim chaine0 As String
Dim chaine1 As String
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDASQL;dsn=PontBasculeTest;uid=PBUser;pwd=PBp@55w0rd;database=PontBasculeTest;"
'initialisation de la fonction
RechercheDouleOption = False
Dim verifier As Recordset
choixglobal = False
Dim f As New frmRecherche1
f.Caption = "RECHERCHE " & UCase(DesigneTable) & " "
f.Show vbModal
If choixglobal Then
If (f.Txtcode.Text = "" And f.Txtlib = "") Then
sqlconnection = "select * from " & DesigneTable & " "
GoTo traitement
End If
chaine0 = IIf(IsNull(f.Txtlib), "%", UCase(f.Txtlib) + "%")
If f.Txtcode <> "" Then
If Not IsNumeric(Trim(f.Txtcode.Text)) Then
MsgBox "Le code doit être numérique", vbExclamation, "PontBascule"
Exit Function
End If
sqlconnection = "select * from " & DesigneTable & " where " & CodeTable & "= " & Trim(f.Txtcode.Text) & " and upper(" & LibTable & ") like '" & chaine0 & "' "
Else
sqlconnection = "select * from " & DesigneTable & " where upper(" & LibTable & ") like '" & chaine0 & "' "
End If
'traitement:
Set verifier = New Recordset
verifier.Open sqlconnection, db, adOpenDynamic, adLockOptimistic
If verifier.EOF Then
neant: MsgBox "Vos options de recherche ne correspondent à aucun enregistrement", vbInformation, "PontBascule"
RechercheDouleOption = False
Exit Function
Else
traitement:
RechercheDouleOption = True
Unload f
End If
End If
End Function |
Partager