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.
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,782
Office Version
  1. 2010
Platform
  1. Windows
Ampersand is the catenation operator.
Code:
If loginfrm.txtUser = "admin" And loginfrm.txtPass = "adminpass"
 
L

Legacy 260294

Guest
Oh. Thank you. It's working at last. You guys are such big help. Thanks Again! :)
 

Watch MrExcel Video

Forum statistics

Threads
1,123,393
Messages
5,601,403
Members
414,449
Latest member
Pashtun

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
Top