Error in coding for login form (1 Viewer)

stephaniechongg

Registered User.
Local time
Today, 22:56
Joined
Feb 5, 2016
Messages
15
Upon running the code, i am unable proceed if I fill in invalid information in both the staffid and staffpassword table

The highlighted is the coding that the system keeps highlighting
Code:
Private Sub Command1_Click()
Dim TempPass As String

If IsNull(Me.txtloginid) Then
  MsgBox "Please enter LoginID", vbInformation, "LoginID Required"
  Me.txtloginid.SetFocus
ElseIf IsNull(Me.txtpassword) Then
  MsgBox "Please enter Password", vbInformation, "Password Required"
  Me.txtpassword.SetFocus
Else
    TempPass = txtloginid.Value
 [COLOR="Red"]   TempPass = DLookup("StaffPassword", "Staff_chelsea", "StaffId = '" & Me.txtloginid.Value & "'")[/COLOR]
   If (TempPass = txtpassword.Value) Then
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Welcome to MINIMALIST"
Style = vbOKOnly
Title = "Welcome"
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbOK Then
    MyString = "ok"
     DoCmd.OpenForm "1_StartNavigationMenu_Steph", acNormal
     DoCmd.Close acForm, "1_Login_Chelsea", acSaveYes
     Else
    MsgBox "Wrong Password/StaffID"
   
 End If
End If
End If
End Sub

I have a database submission due in 8 hours help
 

Ranman256

Well-known member
Local time
Today, 10:56
Joined
Apr 9, 2015
Messages
4,337
IDs are usually numeric, but you have quotes around yours, so ...
Is your ID numeric or string? It will fail here if ID is numeric. Remove the string quotes.
 

stephaniechongg

Registered User.
Local time
Today, 22:56
Joined
Feb 5, 2016
Messages
15
TempPass = DLookup("StaffPassword", "Staff_chelsea", StaffId = & Me.txtloginid.Value)

Do you mean this?
 

Mile-O

Back once again...
Local time
Today, 15:56
Joined
Dec 10, 2002
Messages
11,316
He means this:
Code:
TempPass = DLookup("StaffPassword", "Staff_chelsea", "StaffId = " & Me.txtloginid.Value)


Also, it would be best to use a Nz() on that DLookup, to catch any occasion where you might get an Invalid Use of Null error..

Code:
TempPass = Nz(DLookup("StaffPassword", "Staff_chelsea", "StaffId = " & Me.txtloginid.Value))

Then you could check if the lookup returned a value:

Code:
If TempPass = vbNullString Then
    MsgBox "Password not found"
Else
    [i]...whatever you want[/i]
End If
 

stephaniechongg

Registered User.
Local time
Today, 22:56
Joined
Feb 5, 2016
Messages
15
Hi guys thank you for your kind replies but no matter how much i modify the coding based on your references, the error keeps popping up!!!
 

Users who are viewing this thread

Top Bottom