Microsoft 365 Userform Modification

eric72

XLDnaute Accro
Bonsoir à tous,
J'ai un code qui me permet de modifier des données en passant par un Userform, il fonctionne mais seulement 1 fois sur 2 ou 3, je pensais que ça n'était pas possible mais si je vous assure
Y a t il une boulette??
Voilà a question du soir!!!

Private Sub BtModifPlaque_Click()
'Procédure bouton Modifier
Dim X As Integer, derligne As Integer
If Cells(Rows.Count, 4).End(xlUp).Row = 1 Then
derligne = 2
Else
derligne = Cells(Rows.Count, 4).End(xlUp).Row
End If
For X = 1 To derligne
Application.ScreenUpdating = False
Sheets("Données").Visible = True
Worksheets("Données").Activate
Call Unprotect
If LstPlaque.ListIndex = -1 Then MsgBox "Vous n'avez pas sélectionné de Ligne à Modifier": Exit Sub
If Cells(X, 4) = LstPlaque.List(LstPlaque.ListIndex, 0) Then
Cells(X, 4) = TxtRefPlaque.Value
Cells(X, 5) = CDbl(TxtNbTrouPlaque.Value)
Cells(X, 6) = CDbl(TxtDiamTrouPlaque.Value)
Cells(X, 7) = CDbl(TxtPrixPlaque.Value)
End If
Next X
question = MsgBox("voulez vous Modifier un autre Produit", vbQuestion + vbYesNo, "Information")
If question = vbYes Then
Unload Me
UsfmODIFGeneral.MultiPage1.Value = 3
UsfmODIFGeneral.Show
Else
Unload Me
End If
Call Tri_Tb
Call Protect
Sheets("Données").Visible = False
Application.ScreenUpdating = True
Sheets("Menu").Activate

End Sub
Merci à tous pour votre aide
Eric
 

patricktoulon

XLDnaute Barbatruc
bonsoir
mis a part que l'on a pas de fichier ainsi que les autres fonction qui sont appelées dans cet event
tu a une sérieuse méprise du fonctionnement de cet event

BtModifPlaque fait partie du userform alors
ceci ne peut fonctionner correctement
VB:
f question = vbYes Then
Unload Me
UsfmODIFGeneral.MultiPage1.Value = 3
UsfmODIFGeneral.Show
Else
Unload Me
End If
Call Tri_Tb
Call Protect
Sheets("Données").Visible = False
Application.ScreenUpdating = True
Sheets("Menu").Activate
en effet une fois unloadé le reste de la macro est fichue alors en effet selon l'occupation du processeur et mémoire de ton pc il se peut que de temps en temps le reste de la macro s’exécute ou pas
en tout cas chronologiquement c'est pas bon
car après un unload me on ne doit rien mettre car c'est la fin de l'instance object de l'userform
bref avec un fichier on y verra plus clair je pense
 

eric72

XLDnaute Accro
Bonsoir Patrick TOULON,
Merci pour votre réponse, voilà un fichier simplifié pour pouvoir vous rendre compte.
J'ai toujours du mal à savoir ou situer le unload après une question vbyes no.
Merci bEAUCOUP
Eric
 

Pièces jointes

  • Classeur1.xlsm
    155.1 KB · Affichages: 8

eric72

XLDnaute Accro
Bonjour,
Je ne sais pas si vous avez reçu le fichier (la maintenance du site est intervenue juste après), dans le doute je remet le fichier.
Je me suis que la modification (par exemple sur le prix des pots) ne fonctionne qu'à la deuxième modifiction, pas la première fois, cela me parait très étrange.
Merci encore
Eric
 

Pièces jointes

  • Classeur1.xlsm
    155.1 KB · Affichages: 5

ChTi160

XLDnaute Barbatruc
Bonjour eric72
pas sur d'avoir compris !
lors de l'action du Bouton "Modifier" de la pages "Pots" du Multipage1 la modification apparait ??????
a voir donc
Aussi , tu n'utilises pas toutes les possibilités de tes Tableaux Structurés !
Bonne Journée
Jean marie
 

Pièces jointes

  • Classeur1 (Chti160).xlsm
    152.1 KB · Affichages: 6

eric72

XLDnaute Accro
Bonjour Chti160,
Tout d'abord merci pour votre réponse, le problème est qu'à l'ouverture du Userform, lors de la 1ère modif celle-ci n'est pas prise en compte, puis lors d'un 2ème essai cela fonctionne et après plus de problème.
Je veux dire que la modification n'est pas fiable à 100% Et je ne vois pas pourquoi!!!
Pour les tableaux structurés, c'est juste par manque de connaissance!!!
Merci
Eric
 

eric72

XLDnaute Accro
alors, voilà un exemple précis lorsque je veux modifier sur le fichier d'origine ci-joint
Exemple le prix du pot "D 15 Coupe" le passer de 5 à 6,6, la modification n'est pas prise en compte.
J'espère être assez clair, oups!!!
Ne tombez pas à la renverse si vous regardez la codification...
Je suis juste un petit bricoleur qui essaie de faire bien
Merci
 

Pièces jointes

  • Fiche Produit test.xlsm
    344.3 KB · Affichages: 11

patricktoulon

XLDnaute Barbatruc
re
Bonjour
hoh oui bien trop de boulot
le bouton ajouter qui se bloque lorsque l'on selectionne dans la listbox et si on abandonne ben on est bloquer
et si on ferme en ne faisant rien on a un beau msgbox d'erreur
et c'est comme ça dans tout le fichier
revoir la conception completement
et revoir aussi l'organisation du code voir faire des sub générique pour les textbox par exemple
en effet dans tes textboxs numériques on peut taper 36 virgules ou 36 tirets
on peut metre le tiret ou on veut la virgule aussi d'ailleurs
ce qui veux dire que l'on peut taper une donnée erroné dugenre ",45,56" ou "67-89" rigolo non ?????


donc le controle n'est pas a 100% efficient
à savoir!!!!
le keyascii est un return integer donc en callback il est donc modifiable partout dans n'imorte quel module du classeur y compris le module du userform lui même et cela sans être obligé de le renvoyer a l'event

donc...... a ne pas faire de classe pour 36 textbox qui sont sensés se comporter de la meme maniere perso ( au moins!!)je remplacerais ceci

VB:
Private Sub TxtDiamTrouPlaque_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtCoeffApplique_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPourcentage_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub

Private Sub TxtPrixKgTransVente_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPourcentageComm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPrixKgTrans_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub

Private Sub TxtPrixEmballage_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPrixEtiquette_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPrixPlaque_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPrixPot_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtCoeffTransBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPrixVente_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPrixAccess_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPvLM_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPvAPEX_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPvGAMMVERT_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub TxtPvAUCHAN_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   'TRANSFORMER LE POINT PAR UNE VIRGULE
   If KeyAscii = 46 Then KeyAscii = 44
   If InStr("1234567890,-", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub

par cela et là on a un controle total de la saisie
et le code ne pique pas les yeux 😂
c'est de suite plus net d'un coup
VB:
Function KeyAsciiX(keyascii)
'TRANSFORMER LE POINT PAR UNE VIRGULE
    If keyascii = 46 Then keyascii = 44
    If InStr("1234567890,-", Chr(keyascii)) = 0 Then keyascii = 0
    With ActiveControl
        If InStr(.Value, ",") Then keyascii = 0
        If Chr(keyascii) = "-" And .Value <> "" Then keyascii = 0
    End With
End Function
Private Sub TxtDiamTrouPlaque_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtCoeffApplique_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPourcentage_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPrixKgTransVente_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPourcentageComm_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPrixKgTrans_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPrixEmballage_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPrixEtiquette_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPrixPlaque_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPrixPot_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtCoeffTransBox_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPrixVente_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPrixAccess_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPvLM_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPvAPEX_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPvGAMMVERT_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
Private Sub TxtPvAUCHAN_KeyPress(ByVal keyascii As MSForms.ReturnInteger): KeyAsciiX keyascii: End Sub
 

eric72

XLDnaute Accro
Ok j'ai fait la modif et c'est beaucoup plus clair, pour ce qui est du bouton AJOUTER qui se bloque c'est parce que je ne veux pas prendre le risque qu'après modification d'un des paramètre la personne se trompe et l'ajoute à la base de données mais ce n'est peut être pas la bonne méthode.
Pour le reste les tirets, virgules etc... Je ne connais pas la méthode!!!
Merci beaucoup
Eric
 

Discussions similaires

Réponses
17
Affichages
760

Statistiques des forums

Discussions
311 711
Messages
2 081 799
Membres
101 818
dernier inscrit
tiftouf5757