dates et TextBox

J

janick

Guest
Bonjour,

Je débute en VB ! je rencontre toujours un problemes pour les dates : quand je saisie:

TxB6= 02/12/04 et TxB69= 08/12/04 j'ai un renvoi

02/12/2004 et 12/08/2004

"j'ai déja utilise sur la feuille les divers format text-dates jj/mm/yyyy-standard"

Private Sub TextBox6_change()
Dim form
form = TextBox6
TextBox6 = Format(form, "dd/mm/yyyy")
End Sub

Private Sub TextBox69_Change()
Dim form
form = TextBox69
TextBox69 = Format(form, "dd/mm/yyyy")
End Sub


If datedebut < TextBox69.Value Then
TextBox70 = datefin - datedebut 'pour ce calcul cela fontionne bien

Merci d'avance pour votre aide
 
J

janick

Guest
Bonjour,

Je ne sais pas ci cela suffis

Private Sub TextBox69_AfterUpdate()

Dim datedebut As Date
Dim datefin As Date
On Error GoTo finerreur
datedebut = TextBox6.Value
datefin = TextBox69.Value
If datefin < datedebut Then
MsgBox "La date de fin doit être supérieur ou égale à la date du début !!!"
TextBox69.Value = ""
Else
Dim form
'form = TextBox69
form = CDate(TextBox69.Value)
TextBox69 = Format(form, "dd/mm/yy")
If datedebut < TextBox69.Value Then
TextBox70 = datefin - datedebut

End If
End If
GoTo Fin
finerreur:
MsgBox "format date incorrect"
TextBox69.Value = ""
Fin:
End Sub

merci
 
P

Pascal76

Guest
re

Un peu difficile sans le fichier mais j'essaierai comme ceci :

Private Sub TextBox69_AfterUpdate()

Dim datedebut As Date
Dim datefin As Date
On Error GoTo finerreur
datedebut = cdate(TextBox6.Value)
datefin = cdate(TextBox69.Value)
If datefin < datedebut Then
MsgBox "La date de fin doit être supérieur ou égale à la date du début !!!"
TextBox69.Value = ""
Else
TextBox69 = Format(datefin, "dd/mm/yy")
If datedebut < datefin Then
TextBox70 = datefin - datedebut

End If
End If
GoTo Fin
finerreur:
MsgBox "format date incorrect"
TextBox69.Value = ""
Fin:
End Sub

Pascal
 
J

janick

Guest
bonjour



Dim ladate As Date
ladate = TextBox6.Value
TextBox6.Value = Format(TextBox6.Value, "dd/mm/yyyy")
Worksheets("base").Range("a9") = ladate

Dim ladate2 As Date 'j'ai ajouter cette variable
ladate2 = TextBox69.Value
TextBox69.Value = Format(TextBox69.Value, "dd/mm/yyyy")
Worksheets("base").Range("ag9") = ladate2 'date retour

merci pout tous
 
P

Pascal76

Guest
Re

En fait ton problème vient sur ta validation et non sur ton after update de ton textbox69

donc voici comment changer ton code (j'ai recopié que le début!!!!)

Private Sub CommandButton1_Click() 'valider
Application.ScreenUpdating = False
If TextBox70 = "" Or TextBox7 = "" Or TextBox71 = 0 Or TextBox8 = "" _
Or TextBox10 = "" Or TextBox9 = "" Then
MsgBox "Impossible de valider formulaire incomplet !!"
Exit Sub
Else
Sheets("base").Select
Sheets("base").Range("A9:AH9").Insert Shift:=xlDown
Sheets("base").Range("A9:AH9").Interior.ColorIndex = xlNone
''<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Ici retrait des lignes non indispensables
Worksheets("base").Range("a9") = CDate(TextBox6.Value) ' <<<<Modif ici

Worksheets("base").Range("b9") = TextBox7.Value 'client
Worksheets("base").Range("c9") = TextBox8.Value 'adresse
Worksheets("base").Range("d9") = TextBox10.Value 'ville
Worksheets("base").Range("e9") = TextBox9.Value 'cp
Worksheets("base").Range("f9") = TextBox11.Value 'tel
Worksheets("base").Range("g9") = TextBox13.Value 'fax
Worksheets("base").Range("h9") = TextBox16.Value 'hdebut
Worksheets("base").Range("i9") = TextBox17.Value ' hfin
Worksheets("base").Range("j9") = TextBox14.Value ' manisfestation
Worksheets("base").Range("k9") = TextBox15.Value ' organisation
Worksheets("base").Range("l9") = TextBox18.Value 'lieu
Worksheets("base").Range("ag9") = CDate(TextBox69.Value) 'date retour ' <<<<Modif ici
Worksheets("base").Range("ah9") = TextBox70.Value 'nbjours



Pascal

PS: Pour ton écriture avec lundi 13/12/2004 c'est dans ton fichier (feuille base) ou dans ton UF que tu veux cela ???

PS2 : à l'avenir donne des noms explicites à tous tes contrôles tes UF etc, tu verras c'est plus facile pour travailler avec
 
P

Pascal76

Guest
Re

Pour ta modif d'affichage directement dans le textbox c'est possible mais il faut revoir tout une partie de ton code et changer toute la façon de faire donc ça risque de compliquer

Sinon tu peux peut-être juste créer un petit label au dessus qui t'indique juste le jour sur update de tes textbox ???

Pascal
 

Discussions similaires

Réponses
16
Affichages
687

Statistiques des forums

Discussions
312 615
Messages
2 090 243
Membres
104 464
dernier inscrit
alzerco