Refresh userform

BONJOUR FORUM ,

dans mon code je mets une contrainte dans un textbox ,

la contrainte est : si le champ saisi n'existe pas dans la base on donne l'accès de terminer le travail

sinon (si le champ existe dans la base) il bloque l'utilisateur de terminer le saisi des autres champs.

à ce moment la tous est bien ! mais si je teste un champs existant et aprés un autre non existant il este toujours bloqué , moi je veux rafraîchir le formulaire après chaque saisie interdit !

j'essaie avec

Me.Repaint

et

Load Me 

mais ne fonctionne pas !!!

voila mon code dans le textBox qui contient la contrainte

Private Sub TextBoxLog_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim cell As Range, cell1 As Range
    Dim no_ligne As Integer, i As Integer
    Dim rôles_login_tracés As String, séparateur As String, rôles_login() As String
    Dim ctrl As Control

    With tracing_logins
        Set cell = .ListColumns("Login Windows").Range.Find(Me.TextBoxLog.Value)
      If cell Is Nothing Then: Exit Sub

        '// remplissage contrôles du formulaire
            login_saisi = Me.TextBoxLog.Value
            no_ligne = cell.Row - .HeaderRowRange.Row
           ' MsgBox "Utilisateur existe , a dèja un compte "
           MsgBox "Utilisateur existe dans la base , resaisir un autre "

           '// Désactivation des contrôles
            For Each ctrl In Me.Controls
                If TypeOf ctrl Is MSForms.TextBox Or TypeOf ctrl Is MSForms.ComboBox Then ctrl.Enabled = False
            Next ctrl
            Me.Repaint

            'Me.TextBoxLog.Enabled = True

            End With

End Sub

et pour mieux comprendre ceci la pièce jointe

entrer ----> UserFormCreation

saisir ---->TextBoxLog

53project.xlsm (741.23 Ko)

merci d'avance

Bonjour,

Un essai ...

Private Sub TextBoxLog_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim cell As Range
Dim no_ligne As Integer
Dim ctrl As Control

    With tracing_logins
        Set cell = .ListColumns("Login Windows").Range.Find(Me.TextBoxLog.Value)
        If Not cell Is Nothing Then ' < modif (if Not ...)

            '// remplissage contrôles du formulaire
            login_saisi = Me.TextBoxLog.Value
            no_ligne = cell.Row - .HeaderRowRange.Row

            '// Désactivation des contrôles
            For Each ctrl In Me.Controls
                If ctrl.Name <> "TextBoxLog" Then   ' test pour éviter le 2e msgbox
                    If TypeOf ctrl Is MSForms.TextBox Or TypeOf ctrl Is MSForms.ComboBox Then ctrl.Enabled = False
                End If
            Next ctrl

            MsgBox "Utilisateur existe dans la base , resaisir un autre "
            Me.TextBoxLog = ""      ' vider le textbox
            Me.TextBoxLog.SetFocus  ' lui redonner le focus
        End If
    End With
End Sub

ric

Bonjour,

Pour rafraichir le formulaire :

Call réafficher_formulaire: Unload Me

Bonjour,

Un essai ...

Private Sub TextBoxLog_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim cell As Range
Dim no_ligne As Integer
Dim ctrl As Control

    With tracing_logins
        Set cell = .ListColumns("Login Windows").Range.Find(Me.TextBoxLog.Value)
        If Not cell Is Nothing Then ' < modif (if Not ...)

            '// remplissage contrôles du formulaire
            login_saisi = Me.TextBoxLog.Value
            no_ligne = cell.Row - .HeaderRowRange.Row

            '// Désactivation des contrôles
            For Each ctrl In Me.Controls
                If ctrl.Name <> "TextBoxLog" Then   ' test pour éviter le 2e msgbox
                    If TypeOf ctrl Is MSForms.TextBox Or TypeOf ctrl Is MSForms.ComboBox Then ctrl.Enabled = False
                End If
            Next ctrl

            MsgBox "Utilisateur existe dans la base , resaisir un autre "
            Me.TextBoxLog = ""      ' vider le textbox
            Me.TextBoxLog.SetFocus  ' lui redonner le focus
        End If
    End With
End Sub

ric

merci RIC un bon code et j'élimine quelques instructions ! mais reste une seule chose c'est que le curseur ne retourne pas au TextBoxLog à chaque nouvelle saisie meme avec le

Me.TextBoxLog.SetFocus

voici le nouveau code

Private Sub TextBoxLog_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim cell As Range
Dim no_ligne As Integer
Dim ctrl As Control

    With tracing_logins
        Set cell = .ListColumns("Login Windows").Range.Find(Me.TextBoxLog.Value)
        If Not cell Is Nothing Then  ' < modif (if Not ...)

            '// remplissage contrôles du formulaire
            login_saisi = Me.TextBoxLog.Value
            no_ligne = cell.Row - .HeaderRowRange.Row

            MsgBox "Utilisateur existe dans la base , resaisir un autre "
            Me.TextBoxLog = ""      ' vider le textbox
            Me.TextBoxLog.SetFocus  ' lui redonner le focus

        End If
    End With
End Sub

merciiii d'avance

Bonjour,

Pour rafraichir le formulaire :

Call réafficher_formulaire: Unload Me

comme ça il y a un doublement du formulaire ! et devient lourd !!

Bonjour à tous,

Un essai ...

Private Sub TextBoxLog_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim cell As Range
Dim no_ligne As Integer
Dim ctrl As Control

    With tracing_logins
        Set cell = .ListColumns("Login Windows").Range.Find(Me.TextBoxLog.Value)
        If Not cell Is Nothing Then  ' < modif (if Not ...)

            '// remplissage contrôles du formulaire
            login_saisi = Me.TextBoxLog.Value
            no_ligne = cell.Row - .HeaderRowRange.Row

            MsgBox "Utilisateur existe dans la base , resaisir un autre "
            Me.TextBoxLog = ""      ' vider le textbox
            If Me.TextBoxLog.Value = "" Then Cancel = True
        End If
    End With
End Sub

ric

Bonjour à tous,

Un essai ...

Private Sub TextBoxLog_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim cell As Range
Dim no_ligne As Integer
Dim ctrl As Control

    With tracing_logins
        Set cell = .ListColumns("Login Windows").Range.Find(Me.TextBoxLog.Value)
        If Not cell Is Nothing Then  ' < modif (if Not ...)

            '// remplissage contrôles du formulaire
            login_saisi = Me.TextBoxLog.Value
            no_ligne = cell.Row - .HeaderRowRange.Row

            MsgBox "Utilisateur existe dans la base , resaisir un autre "
            Me.TextBoxLog = ""      ' vider le textbox
            If Me.TextBoxLog.Value = "" Then Cancel = True
        End If
    End With
End Sub

ric

SUPEEEER thank you RIC

ric

Rechercher des sujets similaires à "refresh userform"