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?
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?