Tôi có mã vba tự động mở. Nó thực hiện một số kiểm tra sau đó sẽ nhắc một userform yêu cầu tên người dùng và mật khẩu. Tôi đã gọi cho biểu mẫu này bằng userform_name.show
.Gọi một biểu mẫu người dùng và trả về một giá trị
Vấn đề của tôi là làm cách nào tôi có thể trả lại số Boolean
cho số Auto_Open
phụ của mình từ mã người dùng.
Tôi đã liên kết mã xác minh xem thông tin xác thực có chính xác với nút "Đăng nhập" trên biểu mẫu hay không. đây là mã tạo ra Boolean. Tôi cần trả lại nó cho Auto_Open.
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
"đây là mã tạo boolian" - Nó ở đâu? –
xin lỗi tôi đã thêm nó. làm thế nào tôi có thể vượt qua "bool" trở lại Auto_Open khi mã kết thúc? – user2385809