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 NoClient_AfterUpdate()
On Error GoTo NoClient_Err
'Déclaration des variables
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
'Si le numéro de client est inscrit
If Me.NoClient <> "" Then
'On crée le record pour aller chercher l'adresse selon le numéro du client
strSQL = "SELECT FicheClient.NoClient, NomEntreprise, NomClient, " & _
"AdresseClient, VilleClient, CPClient, Province FROM FicheClient " _
& "WHERE FicheClient.NoClient = '" & Me.NoClient & "';"
Set rst = db.OpenRecordset(strSQL)
'Si le numéro de client correspond à une adresse
If rst.EOF = False Then
If Me.ClientProprio = True Then
Me.AdProprio = rst.AdresseClient
Me.VilleProprio = rst.VilleClient
Me.CPProprio = rst.CPClient
Me.NomProprio = rst.NomClient
Me.ProvProprio = rst.Province
End If
'Si le numéro de client n'est pas dans la base de données
Else
MsgBox "Ce numéro de client n'existe pas!"
Me.NoClient = ""
Me.NoClient.SetFocus
End If
'On libère la mémoire
rst.Close
Set rst = Nothing
End If
db.Close
Set db = Nothing
Exit_NoClient_AfterUpdate:
Me.NoClient.SetFocus
Exit Sub
NoClient_Err:
MsgBox Err.Description
Resume Exit_NoClient_AfterUpdate
End Sub |
Partager