Comment remettre le focus correctement sur un txtbox?

Bonjour à tous,

Voici mon problème j'ai un formulaire qui s'autocomplète en fonction d'une BDD dans un tableur Excel à l'aide de la méthode suivante :

Private Sub nomClient_Change()

    Dim wb As Workbook
    Dim cellfind As Range
    Dim posX As Byte

    If blnStop Then Exit Sub

    Application.ScreenUpdating = False

    posX = nomClient.SelStart

    address = ThisWorkbook.path & "\Outils\AddressBook.HBBx"
    Set wb = Workbooks.Open(address)
    wb.Activate

    Set cellfind = Columns("A").Find(nomClient.Value & "*", cells(2, 1), LookIn:=xlValues, lookat:=xlWhole)
    If Not cellfind Is Nothing Then
        blnStop = True
        nomClient.text = cells(cellfind.row, 1)
        adresseClient.text = cells(cellfind.row, 2)
        cpClient.text = cells(cellfind.row, 3)
        villeClient.text = cells(cellfind.row, 4)
        faxClient.text = cells(cellfind.row, 5)
    Else
        adresseClient.text = vbNullString
        cpClient.text = vbNullString
        villeClient.text = vbNullString
        faxClient.text = vbNullString
    End If

    wb.Close

    Application.ScreenUpdating = True

    nomClient.SelStart = posX
    nomClient.SelLength = Len(nomClient.text)

    nomContact.SetFocus
    nomClient.SetFocus

    blnStop = False

End Sub

Il ouvre le second tableur recherche les données et ensuite la referme. Mais je n'ai plus aucun focus sur mon formulaire qui est un userform. Alors j'appelle via setfocus le champ textbox (nomClient) mais ça ne marche que si j'utilise d'abord un setfocus sur un autre champ avant celui désiré mais le problème c'est que ça se voit... N'y a-t-il pas un autre moyen?

Bien à vous,

Ravens

Personne n'aurait une idée?

Bonjour

Tes fichiers seraient utile

Je viens de bricoler rapidement sur un fichier et je n'ai pas ce problème

Chez toi ça marche si tu supprimes la ligne : "nomContact.SetFocus"?

En tout cas pas chez moi...

18test.zip (32.49 Ko)

Bonjour

Rave a écrit :

Chez toi ça marche si tu supprimes la ligne : "nomContact.SetFocus"?

Et bien non et je ne sais pourquoi

Désolé

Rechercher des sujets similaires à "comment remettre focus correctement txtbox"