Secure Login Form

D

Don

I need to restrict access to certain forms on my database.
Per a similar posting and pursuant to the instructions found at
http://www.databasedev.co.uk/login.html, I have created a similar process for
password verification when entering a form. My problem now is that I need it
to open a particular form as identified in my table when the corresponding ID
and Password are used.

For example, I have a table [tblSecureID] set up with the following fields:
strFunctionID strDescription strPassword strFormName

I have also created the corresponding unbound form [frmSecureLogin] with an
unbound combo box and a text box:
cboFunction txtPassword

On the "go" event, I have the following code:

Private Sub open_form_Click()

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

If IsNull(Me.cboFunction) Or Me.cboFunction = "" Then
MsgBox "You must select a valid function", vbOKOnly, "Required Data"
Me.cboFunction.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 tblSecureID to see if this matches value chosen
in combo box

If Me.txtPassword.Value = DLookup("strPassword", "tblSecureID",
"[strFunctionID]=" & Me.cboFunction.Value) Then

strMyFunctionID = Me.cboFunction.Value

'Close logon form and open restricted area form

Dim stDocName As String
stDocName = DLookup("strFormName", "tblSecureID")

DoCmd.close acForm, "frmSecureLogin", acSaveNo
DoCmd.OpenForm stDocName

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


Everything seems to work really well except when it comes to opening the
correct form [strFormName] that corresponds to the selected function
[strFunctionID]. I believe that my problem lies in how I have the following
statement written:

Dim stDocName As String
stDocName = DLookup("strFormName", "tblSecureID")

DoCmd.close acForm, "frmSecureLogin", acSaveNo
DoCmd.OpenForm stDocName

Because no matter which ID and password I use, it always seems to open the
same form. How can I correct this statement to make it open the form name
that corresponds to the selected function?
 
S

Scott McDaniel

I need to restrict access to certain forms on my database.
Per a similar posting and pursuant to the instructions found at
http://www.databasedev.co.uk/login.html, I have created a similar process for
password verification when entering a form. My problem now is that I need it
to open a particular form as identified in my table when the corresponding ID
and Password are used.

For example, I have a table [tblSecureID] set up with the following fields:
strFunctionID strDescription strPassword strFormName
Everything seems to work really well except when it comes to opening the
correct form [strFormName] that corresponds to the selected function
[strFunctionID]. I believe that my problem lies in how I have the following
statement written:

Dim stDocName As String
stDocName = DLookup("strFormName", "tblSecureID")

DoCmd.close acForm, "frmSecureLogin", acSaveNo
DoCmd.OpenForm stDocName

Because no matter which ID and password I use, it always seems to open the
same form. How can I correct this statement to make it open the form name
that corresponds to the selected function?

You need to add the Third argument to your DLookup, something like this:

stDocName=DLookup("strFormName", "tblSecureID", "strFunctionID='" & strMyFunctionID & "'")


Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
D

Don

Scott, I made the suggested change but now I get a visual basic runtime error
3464 stating there is a data type mismatch in the criteria expression.

In my table [tblSecureID], all controls are set to text with the exception
of strFunctionID which is set to number. Any ideas?
--
Thanks!


Scott McDaniel said:
I need to restrict access to certain forms on my database.
Per a similar posting and pursuant to the instructions found at
http://www.databasedev.co.uk/login.html, I have created a similar process for
password verification when entering a form. My problem now is that I need it
to open a particular form as identified in my table when the corresponding ID
and Password are used.

For example, I have a table [tblSecureID] set up with the following fields:
strFunctionID strDescription strPassword strFormName
Everything seems to work really well except when it comes to opening the
correct form [strFormName] that corresponds to the selected function
[strFunctionID]. I believe that my problem lies in how I have the following
statement written:

Dim stDocName As String
stDocName = DLookup("strFormName", "tblSecureID")

DoCmd.close acForm, "frmSecureLogin", acSaveNo
DoCmd.OpenForm stDocName

Because no matter which ID and password I use, it always seems to open the
same form. How can I correct this statement to make it open the form name
that corresponds to the selected function?

You need to add the Third argument to your DLookup, something like this:

stDocName=DLookup("strFormName", "tblSecureID", "strFunctionID='" & strMyFunctionID & "'")


Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
S

Scott McDaniel

Scott, I made the suggested change but now I get a visual basic runtime error
3464 stating there is a data type mismatch in the criteria expression.

In my table [tblSecureID], all controls are set to text with the exception
of strFunctionID which is set to number. Any ideas?

Try this:
stDocName=DLookup("strFormName", "tblSecureID", "strFunctionID=" & strMyFunctionID)

And I gotta ask ... if strFunctionID is a Number, why do you have it prefaced with "str", which generally means String?

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
D

Don

Works perfectly - Thanks a million.

As for my control having a preface of "str"... I am working with a project
that someone else started and it is full of creative things!
--
Thanks!


Scott McDaniel said:
Scott, I made the suggested change but now I get a visual basic runtime error
3464 stating there is a data type mismatch in the criteria expression.

In my table [tblSecureID], all controls are set to text with the exception
of strFunctionID which is set to number. Any ideas?

Try this:
stDocName=DLookup("strFormName", "tblSecureID", "strFunctionID=" & strMyFunctionID)

And I gotta ask ... if strFunctionID is a Number, why do you have it prefaced with "str", which generally means String?

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 

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