Code Erreur

sten83

XLDnaute Occasionnel
Bonjour je rencontre un petit problème avec un code macro je ne comprend pas?
Ci-joint mon code
Voici le message d'erreur
Erreur d'éxécution -2147024809(80070057):
Objet spécifique introuvable

Merci pour votre aide.

Private Sub CmdValideInfoParc_Click()
Dim i As Byte
For i = 1 To 15
If Controls("TextBox" & i) = "" Then (c'est cette ligne qui pose problème!)
MsgBox "Vous devez remplir le champ " & Controls("label" & i)
Controls("Textbox" & i).SetFocus
Exit For
End If
Next i

With shtjanvier
.Range("AB1") = txtParc.Value
.Range("AB2") = txtCodeParc.Value
.Range("AB3") = txtDirection.Value
.Range("B58") = txtResponsable.Value
.Range("F8") = txtPayant1.Value
.Range("H8") = txtPayant2.Value
.Range("J8") = txtPayant3.Value
.Range("M7") = txtNpayant1.Value
.Range("O7") = txtNpayant2.Value
.Range("Q7") = txtNpayant3.Value
.Range("S7") = txtNpayant4.Value
.Range("U7") = txtNpayant5.Value
.Range("W7") = txtNpayant6.Value
.Range("Y7") = txtNpayant7.Value
.Range("F4") = CboAnnee.Value
.Range("A9") = txtDate.Value

End With
Unload Me

End Sub
 

Paf

XLDnaute Barbatruc
Re : Code Erreur

Re,

Ah ben alors, sûr que ça ne peut pas marcher !

S'il n'y a que ces 15 Textbox sur l'USF, on peut utiliser ce type d'instruction pour remplacer la boucle for i= 1 to 15 :
Code:
For each ctrl in me.controls
    If TypeName(ctrl) = "TextBox" Then
        If ctrl = "" Then 
            MsgBox "Vous devez remplir le champ "   '***& Controls("label" & i) ' 
            ctrl.SetFocus
            Exit For
        end if
     end if
Next
Non testé ( pas de classeur joint)
S'il y avait encore des soucis, joignez un classeur sans données confidentielles.

A+
 

sten83

XLDnaute Occasionnel
Re : Code Erreur

Merci pour la réponse rapide par contre est-il possible de garder ouvert usf tant qu'il reste un champ vide?
Cette fois je joint le classeur, l'usf et usfDonnesParc.
Merci
 

Pièces jointes

  • NOUVEAU_GSM.zip
    272.8 KB · Affichages: 17
  • NOUVEAU_GSM.zip
    272.8 KB · Affichages: 11

Statistiques des forums

Discussions
312 582
Messages
2 089 951
Membres
104 314
dernier inscrit
Tuubibumi