Ouverture multiple d'un userform
Bonjour à tous,
Je suis tout nouveau sur le forum. Je suis un grand fan d'excel mais tout ce que je sais, je l'ai appris seul alors je risque de ne pas être au point sur les termes techniques.
Je suis actuellement en train de faire une application avec visual basic. J'ai mis un accès avec mot de passe, jusqu'ici tout va bien.
Mon souci est le suivant : Lorsque l'utilisateur de mon application met son nom d'utilisateur et son mot de passe, le userform suivant s'ouvre 10 fois... et je ne sais pas pourquoi.
Pour info en fonction du niveau d'accès de l'utilisateur il peut voir le userfom FrmD0, FrmD1 ou FrmD2. Mais le problème est le même pour les trois.
Si quelqu'un a la solution, ça serait ultra cool je ne sais plus quoi faire.
Merci d'avance.
Voici mon code :
Option Explicit
Private Sub BtnRet_Click()
'BOUTON RETOUR PRE ACCUEIL
Unload Me
VBAProject.FrmApr.Show
End Sub
Private Sub BtnQui_Click()
'BOUTON QUITTER
ActiveWorkbook.Save
Application.Quit
End Sub
Private Sub BtnSec_Click()
'CODE D'ACCES PROGRAMME
Dim Ws As Worksheet
Dim Lr As Long
Dim User As String
Dim Mdp As String
Dim connecté As Boolean
Dim Niv As String
Application.ScreenUpdating = False
Set Ws = Sheets("Base")
Lr = Ws.Range("A" & Rows.Count).End(xlUp).Row
connecté = False
If Me.TxbUti = "" Or Me.TxbMdp = "" Then
MsgBox "Veuillez remplir tous les champs"
Exit Sub
End If
User = TxbUti
Mdp = TxbMdp
Dim C As Variant
For Each C In Ws.Range("A2:A" & Lr)
If C = User And C.Offset(, 8) = Mdp Then
connecté = True
Exit For
End If
Next C
Dim i As Long
If connecté = False Then
MsgBox "Vos identifiants sont incorrects"
Me.TxbUti = ""
Me.TxbMdp = ""
Exit Sub
Else
For i = 2 To Lr
Niv = Ws.Cells(i, 10)
If Sheets("Selection").[C2].Value = "" Then
Unload Me
VBAProject.FrmD1.Show
Else
If Sheets("Selection").[C2].Value = 2 Then
Unload Me
VBAProject.FrmD2.Show
Else
Unload Me
VBAProject.FrmD0.Show
End If
End If
Next i
End If
End Sub
Private Sub LblSin_Click()
'LABEL S'INSCRIRE
Unload Me
VBAProject.FrmCcc.Show
End Sub
Private Sub TxbUti_Change()
'RENVOI LA VALEUR DE LA TXTBOX EN A2 DE LA SHEET SELECTION
ActiveWorkbook.Worksheets("Base").ListObjects("TABL").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Base").ListObjects("TABL").Sort.SortFields.Add Key _
:=Range("TABL[[#All],[U]]"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Base").ListObjects("TABL").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Selection").[A2].Value = TxbUti.Text
End Sub
bonjour,
Tu es dans une boucle
For i = 2 To Lr
donc c'est pas étonnant que tes UserForm s'ouvrent tant que Lr n'est pas atteint...
A+
Merci Galopin01, ça fonctionne =)