OVH Cloud OVH Cloud

Fermer UserForm

3 réponses
Avatar
cphil
Bonjour à tous , joyeux Noël,

Sur un UserForm j'ai un ComboBox et un TextBox,
j'essaie de fermer le UserForm en envoyant la touche Echap
avec le code suivant:

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)

If KeyCode = vbKeyEscape Then
Unload UserForm1
End If

End Sub

Ce code fonctionne en mettant le TabStop des contrôles à False,
dés que je donne le focus à l'un ou l'autre des deux contrôles, ça ne
fonctionne plus - ce qui est logique - .....
Comment faire?

Merci A+
--
-cphil-

3 réponses

Avatar
François Picalausa
"cphil" <cazenave.(suffitspam) a écrit dans le message
de news:
Sur un UserForm j'ai un ComboBox et un TextBox,
j'essaie de fermer le UserForm en envoyant la touche Echap
avec le code suivant:



Bonjour/soir,

Sur ta form, ajoute un commandbutton qui aura pour propriété Cancel = True
Dans le code, en supposant que le commandbutton ajouté ait pour nom
CommandButton1, ajoute ceci:
Private Sub CommandButton1_Click()
Unload Me
End Sub

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com
Avatar
cphil
"François Picalausa" a écrit dans le message de
news:
Sur ta form, ajoute un commandbutton qui aura pour propriété Cancel = True
Dans le code, en supposant que le commandbutton ajouté ait pour nom
CommandButton1, ajoute ceci:
Private Sub CommandButton1_Click()
Unload Me
End Sub



Bonjour

Merci François pour ta réponse rapide, ça fonctionne
mais j'aimerais éviter le CommandButton
( j'ai testé avec sa propriété Visble = False pour justement
ne pas le voir ; ça ne fonctionne pas ), est-ce qu'il existe une autre
façon de faire?

Merci.
-cphil-
Avatar
François Picalausa
"cphil" <cazenave.(suffitspam) a écrit dans le message
de news:
"François Picalausa" a écrit dans le message de
news:
Sur ta form, ajoute un commandbutton qui aura pour propriété Cancel
= True Dans le code, en supposant que le commandbutton ajouté ait
pour nom CommandButton1, ajoute ceci:
Private Sub CommandButton1_Click()
Unload Me
End Sub



Bonjour

Merci François pour ta réponse rapide, ça fonctionne
mais j'aimerais éviter le CommandButton
( j'ai testé avec sa propriété Visble = False pour justement
ne pas le voir ; ça ne fonctionne pas ), est-ce qu'il existe une autre
façon de faire?

Merci.
-cphil-



Bojour/soir,

Dans son design, toute feuille devrait comprendre un boutton quitter pour
permettre à l'utilisateur de quitter...

Si tu n'as pas trop de contrôles, tu peux essayer quelquechose comme ceci:
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
TestKeyMain KeyCode.Value
End Sub

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
TestKeyMain KeyCode.Value
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
TestKeyMain KeyCode.Value
End Sub

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
TestKeyMain KeyCode
End Sub

Private Sub TestKeyMain(Key As Long)
If Key = vbKeyEscape Then
Unload Me
End If
End Sub

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com