Creating a simple Login/VBA script in MS Access

W

webmaster

Hi,

I am fairly new to Visual Basic and I am stuck on a little issue. I am
trying to create a login page in MS Access/VBA logs a user with
different privileges into a certain form.

I have a table set up with user names, passwords and user-access
numbers.

I created a form whose record source points to that table.

And I have a Textboxes for "Username" and "Password" plus the login
button.

It sounds fairly simple but I am having trouble getting the database to
find those fields in that table.

I started off trying it more simply by just using the Username. And it
always just pulls up the first record in that table. If I can get it
working with the User_name then I feel that I shouldn't have a problem
with adding the password and restriction rights in there.

I know that I should be using the Security feature with encryption from
within Access. But I find it too complicated to work with. And this
database may be passed on to someone else with less knowledge that
myself (which is a scary thought).

Any help would be thankful. =)

Here's what I've been trying:
My text boxes are called "User_name" and "Pass_word".
And my button is called "Login_Button"
The table is called "User_Access"
And the table fields are called "Username" and "Password".

'---------------------------------
Private Sub Login_Button_Click()

Dim var_login As Variant

var_login = DLookup("[User_Access.UserName]", "User_Access",
"[User_Access.UserName] = [User_name]")

If [UserName] = [User_name] Then

DoCmd.OpenForm "Assign_Request", acNormal

Else

MsgBox ("Incorrect Login")

End If

End Sub
'--------------------

If run it with a MsgBox([UserName]) in the place of the DoCmd, it will
only give me the value for the Username of the first record in the
table.

Should I be using the DLookup command or something else... I am lost
for ideas at this point

Thanks again,


Steven
 
D

David Lloyd

Steven:

One suggestion would be to test the var_login value for nullity. If it
returns null, then the user is not in the table. If it does not return
null, then the user was found in the table. For example:

If Not IsNull(var_login) Then
DoCmd.OpenForm "Assign_Request", acNormal
Else
MsgBox ("Incorrect Login")
End If

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Hi,

I am fairly new to Visual Basic and I am stuck on a little issue. I am
trying to create a login page in MS Access/VBA logs a user with
different privileges into a certain form.

I have a table set up with user names, passwords and user-access
numbers.

I created a form whose record source points to that table.

And I have a Textboxes for "Username" and "Password" plus the login
button.

It sounds fairly simple but I am having trouble getting the database to
find those fields in that table.

I started off trying it more simply by just using the Username. And it
always just pulls up the first record in that table. If I can get it
working with the User_name then I feel that I shouldn't have a problem
with adding the password and restriction rights in there.

I know that I should be using the Security feature with encryption from
within Access. But I find it too complicated to work with. And this
database may be passed on to someone else with less knowledge that
myself (which is a scary thought).

Any help would be thankful. =)

Here's what I've been trying:
My text boxes are called "User_name" and "Pass_word".
And my button is called "Login_Button"
The table is called "User_Access"
And the table fields are called "Username" and "Password".

'---------------------------------
Private Sub Login_Button_Click()

Dim var_login As Variant

var_login = DLookup("[User_Access.UserName]", "User_Access",
"[User_Access.UserName] = [User_name]")

If [UserName] = [User_name] Then

DoCmd.OpenForm "Assign_Request", acNormal

Else

MsgBox ("Incorrect Login")

End If

End Sub
'--------------------

If run it with a MsgBox([UserName]) in the place of the DoCmd, it will
only give me the value for the Username of the first record in the
table.

Should I be using the DLookup command or something else... I am lost
for ideas at this point

Thanks again,


Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top