I have a problem with my log in form in VBA Excel?

L

Legacy 260294

Guest
Hi, I'm new here. I have encountered a problem in my project. I tried to make a log in form which connects to my project which is a School Library System. I have 2 Textboxes and a Command Button. I entered the correct details in the textboxes. But the code doesn't work. I used If-Then-ElseIf in using my Log in form. And it always runs the Else part. Here is the code:

Code:
If loginfrm.txtUser = "admin" & loginfrm.txtPass = "adminpass" Then    Unload Me
    mainfrm.datetime.Caption = "Logged In at  " & Now
    mainfrm.welcome.Caption = "Welcome, Admin!"
    mainfrm.Show


ElseIf txtUser = "librarian" & txtPass = "libpass" Then
    Unload Me
    mainfrm.Delete1.Enabled = False
    mainfrm.datetime.Caption = "Logged In at  " & Now
    mainfrm.welcome.Caption = "Welcome, Librarian!"
    mainfrm.Show
Else
    MsgBox "Wrong Username/Password. Try Again.", vbCritical, "Error."
End If

I would like to know what is going on in my project. Please help me.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Ampersand is the catenation operator.
Code:
If loginfrm.txtUser = "admin" And loginfrm.txtPass = "adminpass"
 
Upvote 0
Oh. Thank you. It's working at last. You guys are such big help. Thanks Again! :)
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top