Titre du sujet : Re: Calcul de dates dans un USF par myDearFriend! le 15/04/2012 20:32:36
Re,
Oui, je pense que tu as bien compris le principe.
Les 2 conditions sont :
- Le mDF XLcalendar doit être installé sur la machine utilisateur.
- Une référence à ce complément doit être faite dans le projet VBA.
Ci-joint le fichier de départ modifié pour utiliser le mDF XLcalendar (si ce complément est bien présent sur la machine) :
J'ai remplacé les lignes de code suivantes :
Private Sub txtDu_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = KeyNumOnly(KeyAscii)
End Sub
Private Sub txtAu_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = KeyNumOnly(KeyAscii)
End Sub
Private Sub txtReeng_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = KeyNumOnly(KeyAscii)
End Sub
Private Function KeyNumOnly(ByVal K As Integer) As Integer
'Autorise uniquement les touches numériques de 0 à 9 (renvoyées par Keypress)
If K < 48 Or K > 57 Then K = 0
KeyNumOnly = K
End Function
Private Sub txtDu_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim T As String
T = FormatDate(txtDu.Text)
If T <> "" Then
txtDu.Text = T
CalculValid 'calcul et autorisation de validation
Else
Cancel = True 'le focus reste sur le textbox pour correction
End If
End Sub
Private Sub txtAu_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim T As String
T = FormatDate(txtAu.Text)
If T <> "" Then
txtAu.Text = T
CalculValid 'calcul et autorisation de validation
Else
Cancel = True 'le focus reste sur le textbox pour correction
End If
End Sub
Private Sub txtReeng_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim T As String
T = FormatDate(txtReeng.Text)
If T <> "" Then
txtReeng.Text = T
CalculValid 'calcul et autorisation de validation
Else
Cancel = True 'le focus reste sur le textbox pour correction
End If
End Sub
Private Function FormatDate(D As String) As String
'insèrer les /
If Len(D) = 8 Then
D = Left(D, 2) & "/" & Mid(D, 3, 2) & "/" & Mid(D, 5)
If IsDate(D) Then FormatDate = D
ElseIf Len(D) = 10 And IsDate(D) Then
FormatDate = D
End If
End Function
... par celles-ci :
Private Sub txtAu_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = True
mDFXLcalShow CalCtrl:=txtAu
CalculValid
End Sub
Private Sub txtDu_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = True
mDFXLcalShow CalCtrl:=txtDu
CalculValid
End Sub
Private Sub txtReeng_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = True
mDFXLcalShow CalCtrl:=txtReeng
CalculValid
End Sub
Et pour sécuriser l'ensemble, j'ai appliqué la propriété Locked = True aux TextBox pour empêcher une saisie manuelle des dates (qui, du coup, ne serait plus contrôlée).
Si tu penses avoir reçu la réponse qui te convient, merci de mettre en pratique ce qui est inscrit au bas de ma signature.
Cordialement,
|