VBA

pegou Messages postés 13 Date d'inscription jeudi 3 janvier 2008 Statut Membre Dernière intervention 17 juillet 2008 - 3 janv. 2008 à 14:38
pegou Messages postés 13 Date d'inscription jeudi 3 janvier 2008 Statut Membre Dernière intervention 17 juillet 2008 - 7 janv. 2008 à 18:14
bonjour à tous
j ai donc une petite question sur une programmation en vba.
je pose le pb :
dans une userform j ai plusieurs commandboutton et plusieurs textbox
je voudrai que lorsque je clic sur un commandboutton une inscription s'inscrive dans la 1° textbox (jusque la c ok ) mais si la 1° textbox est non vide aller voir la 2° et ainsi de suite.
j ai une 10ene de textbox et encore plus de commandboutton.
 si vous avez une idee
merci
bye - bye  [Insert_Emoticon('/imgs2/smile_wink.gif'); ]

11 réponses

cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
3 janv. 2008 à 14:47
Salut,

Moi, je ferais un truc du genre :

Private Sub Form_Load()


Dim oCtrl As Control


For Each oCtrl In Me
    If TypeOf oCtrl Is TextBox Then
       If oCtrl.Text = vbNullString Then
          oCtrl.Text = "CeQueTuVeux"
       End If
    End If
Next oCtrl


End Sub


A+
Exploreur

 Linux a un noyau, Windows un pépin


 
0
pegou Messages postés 13 Date d'inscription jeudi 3 janvier 2008 Statut Membre Dernière intervention 17 juillet 2008
3 janv. 2008 à 16:22
merci exploreur
je suis nouveau en prog alors dans un premier temps je vais analyser mais je voi que tu ne nomes pas de textbox dans ta procedure et je voudrai faire une boucle de la textbox1 à textbox10 et pouvoir copier cette procédure dans tous mes commandboutton
mon prog :
private sub commandboutton1_click()
if textbox1.value=("") then textbox1.value=("XY")
end if
end sub
bye - bye  [Insert_Emoticon('/imgs2/smile_wink.gif'); ]
0
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
3 janv. 2008 à 16:36
Re,

Alors je te propose un autre truc, essaye, regarde....

Private Sub Command1_Click()
       '* Appel sub qui va vérifier
       '* Si ta zone est "vide" ou pas
          TxtEmpty Text1
          'TxtEmpty Text2
          'TxtEmpty Text3
          'TxtEmpty Text4
End Sub


Private Sub TxtEmpty(oTxt As Control) ' Sub de vérification ZoneTxt
       '* test de vérification de la zone       If oTxt.Value vbNullString Then oTxt.Value "Toto"       'If oTxt.Text vbNullString Then oTxt.Text "Toto"
End Sub


A+
Exploreur

 Linux a un noyau, Windows un pépin


 
0
pegou Messages postés 13 Date d'inscription jeudi 3 janvier 2008 Statut Membre Dernière intervention 17 juillet 2008
3 janv. 2008 à 16:58
ok
je vais faire des essais
merci pour le tuyau
a+

bye - bye  [Insert_Emoticon('/imgs2/smile_wink.gif'); ]
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
3 janv. 2008 à 17:40
salut,
ne pas oublier le exit for après avoir "trouvé" la zone vide
0
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
3 janv. 2008 à 20:52
Salut PCPT,

Oui, effectivement on peut rajouter le Exit For dans la boucle....Je ne l'ai pas mis, car comme il voulait parcourir ses 10 zones de texte, c'est pour çà que j'azi fait ainsi, mais on peut encore modifier aussi comme cela :

Private Sub Command1_Click()


       '* Appel Sub
        TxtEmpty Text1, "TuEcrisCeQueTuVeuxZone1"
       
End Sub


Private Sub TxtEmpty(oTxt As Control, sString As String)


       '* Déclaration
        Dim oCtrl As Control


       '* Boucle sur tout Ctrl Txt de ton formulaire
        For Each oCtrl In Me
            If TypeOf oCtrl Is TextBox Then
               If oCtrl.Text = vbNullString Then
                  oCtrl.Text = sString
                  '* Sort de la boucle dès la
                  '* Première zone vide rencontrée
                   Exit For
               End If
            End If
        Next oCtrl
       
End Sub


A+
Exploreur

 Linux a un noyau, Windows un pépin


 
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
3 janv. 2008 à 21:00
Explo
(bonjour) -> alors à quoi te sert l'argument oTxt ?
0
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
3 janv. 2008 à 21:11
!!PAF!!









Private Sub Command1_Click()


       '* Appel Sub
        TxtEmpty "TuEcrisCeQueTuVeux"
       
End Sub


Private Sub TxtEmpty(sString As String)


       '* Déclaration
        Dim oCtrl As Control


       '* Boucle sur tout Ctrl Txt de ton formulaire
        For Each oCtrl In Me
            If TypeOf oCtrl Is TextBox Then
               If oCtrl.Text = vbNullString Then
                  oCtrl.Text = sString
                  '* Sort de la boucle dès la
                  '* Première zone vide rencontrée
                   Exit For
               End If
            End If
        Next oCtrl
       
End Sub






A+
Exploreur

 Linux a un noyau, Windows un pépin


 
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
3 janv. 2008 à 21:21
re,
ok.. alors mis à part que tu en as fais une sub et que la chaîne passe par un param, quelle est la différence avec ta première proposition?

(re PAF )
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
3 janv. 2008 à 21:41
bon j'vais quand même participer..

Public Sub FillTB(ByVal oParent As Object, ByVal sTextBox As String, ByVal sStr
As String, ByVal iFrom As Integer, ByVal iTo As
Integer)
    On Error GoTo ErrHandler
    
    Dim oTB As Object
    Dim Index As Integer

    For Each oTB In oParent '
boucle sur touts les Ctrl d'un formulaire (normalement)
        If TypeOf oTB Is TextBox Then ' c'est bien une
txtbox
            Index = CInt(RightB(oTB.Name, LenB(oTB.Name) - LenB(sTextBox))) 'indice
            If Index >= iFrom And Index <= iTo Then 'on a le bon indice
                If LenB(oTB.Text) = 0 Then 'la zone est
vide
                    oTB.Text = sStr
                    Exit For 'zone modifiée, on
quitte
                End If
            End If
        End If
    Next oTB
    
    
ErrHandler:
    Set oTB = Nothing
    Err.Clear
End Sub

'   s'utilise
avec....
FillTB Me, "Text", "bonjour", 2, 5

celà dit il faut savoir qu'en aucun cas on ne peut être CERTAIN que la collection retournée (for each) sera triée par ordre alphabétique, donc aucune raison de croire que TEXT3 vide sera forcément remplie (et trouvée) si TEXT4 est vide aussi .....

++
<hr size="2" width="100%" />Prenez un instant pour répondre à [infomsg_SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp
0
pegou Messages postés 13 Date d'inscription jeudi 3 janvier 2008 Statut Membre Dernière intervention 17 juillet 2008
7 janv. 2008 à 18:14
merci PCPT
etant nouveau en programmation tous les termes ne me parle pas encore....
je vais etudier ce que tu m'as donne

bye - bye  [Insert_Emoticon('/imgs2/smile_wink.gif'); ]
0
Rejoignez-nous