Log In system using VBA in a form (1 Viewer)

MBJD

New member
Local time
Today, 00:51
Joined
Jan 9, 2013
Messages
6
Hi guys would really appreciate some help here.

I've created a database and I'm trying to make a log-in screen for it. I've currently got a table named "tbl_SystemUsers"

For the Log In form, I've got Username (Combo10) and Password (Text 2) fields. Every time I click the log in button I get error 424 (object not found)

My exact script for the click of Log In (Command12) is:

Code:
Private Sub Command12_Click()



    'Check value of password in tblSystemUsers to see if this
    'matches value chosen in combo box
    
 
  If Text2.Value = DLookup("[Password]", tbl_SystemUsers, "[UserID]=" & UserName.Value) Then
    
        UserID = UserName.Value

        'Close logon form and open splash screen

        DoCmd.Close acForm, "frm_LogIn", acSaveNo
        DoCmd.OpenForm "frm_StartUp"

    Else
      MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
        Text2.SetFocus
    
    
    End If

 
End Sub

When I hover the mouse over tbl_SystemUsers, it says that is empty.

Any help would be appreciated, bit of a newb in this area so any help would be fantastic.

Thanks
 

cwald

Registered User.
Local time
Yesterday, 18:51
Joined
Jan 3, 2013
Messages
12
put quotes around the table name "tbl_SystemUsers"
 

cwald

Registered User.
Local time
Yesterday, 18:51
Joined
Jan 3, 2013
Messages
12
I may be wrong but I would try this
DLookup("[Password]", tbl_SystemUsers, "[UserID]='" & UserName.Value & "'"

when you have a numeric value you sometimes need a single quote around the value.
 

MBJD

New member
Local time
Today, 00:51
Joined
Jan 9, 2013
Messages
6
I may be wrong but I would try this
DLookup("[Password]", tbl_SystemUsers, "[UserID]='" & UserName.Value & "'"

when you have a numeric value you sometimes need a single quote around the value.

Still not working ahah :(
 

cwald

Registered User.
Local time
Yesterday, 18:51
Joined
Jan 3, 2013
Messages
12
i did a search in access this is the correct dlookup format

DLookup("[LastName]", "Employees", "[EmployeeID] = 1")

Notice the quotes around the table name.
in the example they hard coded the number 1 or Employeid, this is a good way to debug your code.

After looking at your code again what is line UserID = UserName.Value used for??

UserID is not defined, so the error would be correct.
 

cwald

Registered User.
Local time
Yesterday, 18:51
Joined
Jan 3, 2013
Messages
12
when you get the error and you click on the debug button what is highlighted?
 

cwald

Registered User.
Local time
Yesterday, 18:51
Joined
Jan 3, 2013
Messages
12
here is someone elses response to a earlier post

For text data:
dlookup ("Field1Name", "TableName", "[Field2Name] ='" & SomeVariable & "'")

For Date data;
dlookup ("Field1Name", "TableName", "[Field2Name] =#" & SomeVariable & "#")

For numeric data;
dlookup ("Field1Name", "TableName", "[Field2Name] =" & SomeVariable)
 

MBJD

New member
Local time
Today, 00:51
Joined
Jan 9, 2013
Messages
6
when you get the error and you click on the debug button what is highlighted?

Code:
DLookup("[Password]", tbl_SystemUsers, "[UserID]='" & UserName.Value & "'"
is highlighted

I tried the text data type (as passwords can contain letters/numbers) but I'm still getting the same error
 

cwald

Registered User.
Local time
Yesterday, 18:51
Joined
Jan 3, 2013
Messages
12
still need the quotes around the table name.. That i'm sure of.
 

Strike_Eagle

Registered User.
Local time
Yesterday, 18:51
Joined
Oct 20, 2011
Messages
48
Don't forget to close the parenthesis!
Code:
DLookup("[Password]", "tbl_SystemUsers", "[UserID]='" & UserName.Value & "'"[B][COLOR=red])[/COLOR][/B]
 
Last edited:

MBJD

New member
Local time
Today, 00:51
Joined
Jan 9, 2013
Messages
6
Don't forget to close the parenthesis!
Code:
DLookup("[Password]", "tbl_SystemUsers", "[UserID]='" & UserName.Value & "'"[B][COLOR=red])[/COLOR][/B]

Still having problems :eek:
 

cwald

Registered User.
Local time
Yesterday, 18:51
Joined
Jan 3, 2013
Messages
12
when the application hanges and you go the code window, type in the immediate window ?username.value and hit enter it should give you what the value will be in your combobox, correct?

if you don't see the Immediate window go to menu item View and select the Immediate window, this will open the window. this works great in debugging your code that is hanging.

I'm thinking your combobox is bound to a column that does not contain your userid value.
 

Users who are viewing this thread

Top Bottom