login table and login form

K

kennytwk

hi i'm new here

i have a login table with user name and password, and a form that require
a username and password to trigger another form, i have connected my form to
the table, can anyone tell me how do i make my form and table work the way we
log in into this forum?? thanks, i know how to do it in java but i'm new to
vba in access
 
D

Damon Heron

If I understand correctly, you want the login form to come up when the db is
opened? Select Tools, Startup, and put the name of the form where it says
Display form/page.

HTH
Damon
 
K

kennytwk via AccessMonster.com

no :), i'm to build a login feature to my access application, i need my form
to verify the table and authenticate then user. if valid another form will
prompt out.
 
D

Damon Heron

Explain what you mean by "verify the table"? When you open the form, you
can have a combobox for user name and textbox for password that is stored in
the table. The combobox has a row source tied to the table - "SELECT
tblUser.UserID, tblUser.UserName, tblUser.EncryptedPassword FROM tblUser
ORDER BY tblUser.UserName;"

The form's code is like this:

Private Sub cmdChkPwd_Click() ' this is a command button click event that is
on the form
If Me.txtPwd = Me.cboLogin.Column(2) Then ' textbox for password and
combobox for username
DoCmd.Close acForm, "frmLogon" 'this is the login form
DoCmd.openform "frmSplash" ' this is the form that will open after
successful logon

Else
If ct < 4 Then 'this gives four chances
MsgBox "Password not recognized. Try again!", vbOKOnly, "WineWorks"
ct = ct + 1
Else
DoCmd.Quit
End If
End If
End Sub

In the form's module, you need:
Option Compare Database
Dim ct As Integer ' this is the counter for the number of logon attempts.
***************

This is really light security. If you need more security, then consider
workgroups, or sql server. The above code can be fairly secure if you
disable the bypass key and make an mde file, though.

HTH
Damon
 
K

kennytwk via AccessMonster.com

Thanks, what i mean is i have 2 text box,
the first 1 is for the user to key in the username, the second is for the
password, for normal authentication, it act like the way we log into hotmail
or this forum, i have a table, each records have a username and password, if
the record match to the one that the user key into the text boxs, access is
valid, else invalid access to my system,

i think i get what u mean, i have been going through some books to connect
database with ADO, i will try first on my own, thanks, ur code gave me some
idea though :)

btw about the may i know what u mean by workgroups? is it some setting in MS
Access?,

i have another authentication process where "many user to one ID and
password", which mean multiple user will be using the same "username and
password" to login to an application at the same time, those user can only
"view" whatever that is available in the application, no updating or editing
priviledge is given to them. is it using the "same module" as the 1 above?
can anyone give me some idea? thanks.
 
D

Damon Heron

Type "Workgroups" in Access Help. you'll get lots of information on
security there. It's not for the faint of heart though. Make sure you
thoroughly understand it before implementing it.

Damon
 
K

kennytwk via AccessMonster.com

Hi, can anyone tell me where me where i went wrong?, i'm new to vba, the code
may look terrible to u guys, thanks, i have a table "Login" with 2 field
"Username, Password". Another 2 text box, Text0_Username and Text2_Password.

Private Sub Command5_Click()
On Error GoTo Err_Command5_Click

Dim ct As Integer
Dim cmd5 As ADODB.Command
Dim rst1 As ADODB.Recordset
Dim str1 As String
Dim fld1 As ADODB.Field
Dim stDocName As String
Dim stLinkCriteria As String

Set cmd5 = New ADODB.Command
With cmd5
.ActiveConnection = CurrentProject.Connection
.CommandText = "SELECT Username, Password FROM LOGIN"
.CommandType = adCmdText
End With

Set rst1 = cmd5.Execute
Do Until rst1.EOF
str1 = ""
For Each fld1 In rst1.Fields
str1 = str1 & fld1.Value & vbTab
Next fld1
rst1.MoveNext
Loop



If (Text0 = fld1 & Text2 = fld1) Then
stDocName = "Project"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
If ct < 4 Then
MsgBox "Password not recognized. Please Try again!", vbOKOnly
ct = ct + 1
Else
DoCmd.Quit
End If
End If

rst1.Close
Set fld1 = Nothing
Set rst1 = Nothing
Set cmd5 = Nothing

Exit_Command5_Click:
Exit Sub


Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

End Sub
 
D

Damon Heron

You are making it way too difficult.

First the table -I would have three fields: UserID, UserName, Password.
(UserID is an autonumber as primary key). Password field has an input mask
of "Password". This hides the actual password from prying eyes.
Now the form - why have users type in their name each time? Make the User
textbox a combobox instead, and

set the row source (in Properties) to the following: SELECT Login.UserID,
Login.UserName, Login.Password FROM Login ORDER BY Login.UserName;

Then set the combobox format properties:
ColumnCount to 3,
ColumnWidths to 0";1";0" (this stores the values UserID, name and Password,
but only shows the UserName. So combobox1.column(0) is the UserID,
column(1) is the name, and column(2) is the password.

Finally set the input mask of the textbox to "Password" so what the user
types doesn't show on the screen.

Now the user types in the password in text2, and the command button, when
clicked, checks the textbox against combobox.column(2), and if they match
entry is allowed.
So the command button code is only this: (note that I give them more
descriptive names: your text2 is txtPwd, combobox is cboLogin)

Private Sub Command5_Click() ' left off error check for brevity
If Me.txtPwd = Me.cboLogin.Column(2) Then
curUser = Me.cboLogin.Column(0)
DoCmd.Close acForm, "LogonForm"
DoCmd.openform "Your Project Form"
Else
If ct < 4 Then
MsgBox "Password not recognized. Try again!", vbOKOnly, "My Project"
ct = ct + 1
Else
DoCmd.Quit
End If
End If
End Sub

Note also the the "ct" variable is not is this click event! Assign the
variable at the form level, up where it says "Option Compare Database" - the
reason is if it was inside the click event it would never reach 4 since each
click would re-initialise it to zero.

Damon
 
K

kennytwk via AccessMonster.com

yup, thanks for the help, i think i am getting the hang of it,
thanks again :)
 

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

Similar Threads

Login to an Access Application 4
login form 1
Click on website button with tag "button" 0
Record UserID in form 8
Data entry for a table from a form 1
Search form via filter 5
Users log 4
Login Help! 2

Top