using command button to verify user name/pass and open his record

akshayjoshi222

Registered User.
Local time
Today, 18:35
Joined
Mar 14, 2010
Messages
11
pls help,
i have a table "pdp" containing following fields-
Serial Number
Employee Id
Name
EmpPass
made a form "Training" containing-
combo box-takes values from "pdp" table(Name field)
text box-user puts password in it
command button-it checks entry made in combo box and text box,verifies it with "pdp" table,and opens another form containing all records.
the problem is i want it to open specific record bases on value in combo box.
Code is-
Private Sub cmdLogin_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.EmpName) Or Me.EmpName = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.EmpName.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this
'matches value chosen in combo box

If Me.txtPassword.Value = DLookup("EmpPass", "EmpDetails", _
"[EmpID]=" & Me.EmpName.Value) Then

MyEmpID = Me.EmpName.Value

'Close logon form and open splash screen

'DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "pdp"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub
 
What you are attempting to do is something that can be done, but there are a couple of things the you need to consider before you assume that what you are doing is really "secure". If this is only to keep curious eyes out, the it may be sufficient. Only you, the developer, can know the extent to which you need to go to secure your applicaiton.

Are you aware that unless you specifically address the issue, anyone can circumvent your security by simply holding down the Shift key when opening the database and the entire process will be by passed?

With all that said, to specifically answer your question; take a look at the "DoCmd.OpenForm" line and use the "Where" parameter to specify the record to be displayed.

Assuming that your variable "MyEmpID" has been declared as a Long type variable, you can use a line of code like:

Docmd.OpenForm ""pdp", , , "NameOfFieldInFormsRecordSource = " & MyEmpID & ""
 
i'm using
DoCmd.OpenForm "pdp",,,"[EmpName]=" & Me.EmpName
error generates-data type mismatch,
what should i do
 
If [EmpName] is of type String then you need to surround Me.EmpName in single quotes:

Code:
DoCmd.OpenForm "pdp",,,"[EmpName]= [B][COLOR=Red]'[/COLOR][/B]" & Me.EmpName & "[B][COLOR=Red]'[/COLOR][/B]"
 
If [EmpName] is of type String then you need to surround Me.EmpName in single quotes:

Code:
DoCmd.OpenForm "pdp",,,"[EmpName]= [B][COLOR=Red]'[/COLOR][/B]" & Me.EmpName & "[B][COLOR=Red]'[/COLOR][/B]"

thnks for evryone's precious time
 
You're welcome. Thanks to Mr. B for giving you the syntax. Glad you got it sorted.
 

Users who are viewing this thread

Back
Top Bottom