By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,635 Members | 911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,635 IT Pros & Developers. It's quick & easy.

I want to use "if then else" function

P: 1
Expand|Select|Wrap|Line Numbers
  1. If [Loginpassword]=[password] then
  2. Docmd.openform"form1"
  3. else
  4. MsgBox(wrong login).
the first part is not working,not open the form,what is wrong?
Jun 4 '17 #1
Share this Question
Share on Google+
2 Replies


PhilOfWalton
Expert 100+
P: 1,430
You're a bit short of information.
I assume the LoginPassword is typed in and the code you are trying to run occurs on the after update of that field.

Where does the Password data come from?

Here is some code I use, but there is a table of users and their passwords, and the person trying to log in has to select their name first and hence their UserID

This code is a modification of the code I use, so is not guaranteed.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Compare Database
  3. Option Explicit
  4.  
  5.     Dim Tries As Integer
  6.  
  7.     Private Declare PtrSafe Function GetKeyState Lib "user32" _
  8.         (ByVal nVirtKey As Long) As Integer
  9.  
  10. Function GetCapslock() As Boolean
  11.     'Return the CapsLock Value
  12.  
  13.     GetCapslock = CBool(GetKeyState(vbKeyCapital) And 1)
  14.  
  15. End Function
  16.  
  17. Private Sub LoginPassword_AfterUpdate()
  18.  
  19.     Dim UserPass As String
  20.  
  21.     If Nz(LoginPassword) = "" Then
  22.         Exit Sub
  23.     End If
  24.  
  25.     UserPass = ELookup("LoginPassword", "Users", "UserID = " & UserID)
  26.  
  27.     If StrComp(UserPass, LoginPassword, vbBinaryCompare) = 0 Then
  28.         Docmd.openform "form1"                         ' Open the menu
  29.     Tries = 0
  30.     Else
  31.         If GetCapslock() = True Then
  32.            Msgbox "The Caps Lock is on", VbInformation
  33.         Else
  34.             Mshbox "Wrong Password. - Please re-enter", VbInformation
  35.         End If
  36.         Tries = Tries + 1
  37.         If Tries > 3 then
  38.             DoCmd.Quit
  39.         End If
  40.    End If
  41.  
  42.  
This password check is case sensitive and gives a warning if Caps lock is on. It is also up to you what you want to do after 3 unsuccessful tries.

Phil
Jun 4 '17 #2

NeoPa
Expert Mod 15k+
P: 31,409
Please read How to ask "good" questions -- READ BEFORE SUBMITTING A QUESTION!.

Your question looks like you've done no preparation for it at all.
Jun 4 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.