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 49 50 51 52
|
Private Sub Button_Add_Customer_Click()
If (ChampObligatoir(Me) = True) Then
Else
'Requete SQL
DoCmd.RunSQL ("INSERT INTO customer(company,sector,WebSite,informations) values " _
& " ('" & Me.TextBox_Company.Value & "','" & Me.TextBox_Sector.Value & "', '" & Me.TextBox_WebSite & "', " _
& " '" & Me.TextBox_AddInf.Value & "')")
'Message de confirmation
MsgBox "This cutomer has been succesfully added to the database", vbOKOnly, "Success"
'Remet le focus sur textbox company apres avoir validé
Me.TextBox_Company.SetFocus
'Reinitialise les champs du formulaires apres avoir validé
Call Instruction.Reinitialisation(Me)
End If
End Sub
Public Function ChampObligatoir(frmMe As Form) As Boolean
Dim i As Long
For i = 0 To frmMe.Controls.Count - 1
Debug.Print TypeName(frmMe.Controls(i))
'Verifie que le Tag du control n'est pas null
If Trim(frmMe.Controls(i).Tag) <> "" Then
Select Case TypeName(frmMe.Controls(i))
Case "TextBox"
If Trim(frmMe.Controls(i)) = "" Then
MsgBox "You need to enter " & frmMe.Controls(i).Tag, vbOKOnly, "Error"
frmMe.Controls(i).SetFocus
ChampObligatoir = True
End If
Case "ListBox"
If Trim(frmMe.Controls(i)) = "" Then
MsgBox "You need to enter " & frmMe.Controls(i).Tag, vbOKOnly, "Error"
frmMe.Controls(i).SetFocus
ChampObligatoir = True
End If
End Select
End If
Next
End Function |
Partager