Ho un codice VBA che è Auto_apri. Fa alcuni controlli quindi richiede un userform che richiede nome utente e password. Ho chiamato questo userform con userform_name.show
.Chiamare un userform e restituire un valore
Il mio problema è come è possibile restituire un Boolean
al mio sub Auto_Open
dal codice utente.
Ho collegato il codice che verifica se le credenziali sono corrette sul pulsante "Login" nel modulo. questo è il codice che produce il booleano. Devo restituirlo a Auto_apri.
Private Sub loginbutton()
Dim bool As Boolean
Dim lrup
Dim r As Long
Dim pass As String
loginbox.Hide
'are fields empty
Do While True
If unBox.Text = "" Or pwBox.Text = "" Then
MsgBox ("You must enter a Username and Password")
Else
Exit Do
End If
loginbox.Show
Exit Sub
Loop
'find pw reated to username (if existant)
lrup = UserPass.Range("A1").Offset(UserPass.Rows.Count - 1, 0).End(xlUp).Row
If unBox = "b0541476" And pwBox = "theone" Then
bool = True
Else
MsgBox ("Invalid username or password. Please try again.")
loginbox.Show
Exit Sub
End If
For r = 2 To lrup
If unBox = Cells(r, 1) Then
pass = Cells(r, 2).Value
Exit For
End If
Next
If pass = "" Then
MsgBox ("Invalid username or password. Please try again.")
loginbox.Show
Exit Sub
Else
bool = True
End If
End Sub
"questo è il codice che produce il boolian" - Dove si trova? –
scusa l'ho aggiunto. come posso passare "bool" a Auto_apri quando il codice è finito? – user2385809