Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login screen

Status
Not open for further replies.

mabaulza

IS-IT--Management
Oct 25, 2004
12
0
0
GB
I have a login screen created by the follwing VBA coding on the command button:

Private Sub cmdLogin_Click()

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

If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.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("strEmpPassword", "tblUsers", "[lngEmpID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value

'Example msgbox to display result of function

' MsgBox "The employee ID is: " & lngMyEmpID
'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmMainPage"

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 your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub

I need to basically say, if a user has a string access (found in tblusers) of Admin then open frmMainPage, if user has a string access of User then open frmRequest.

can anyone tell me how to do this, my vba is weak!
 
Just my guess... as my vba is also weak...
but could you add a Dlookup in the password (true) section to save the value of your string access for user X then in the DoCmd.OpenForm "frmMainPage" then before DoCmd.OpenForm "frmMainPage" have another if statment saving the form to open in a variavle and change "frmMainPage" to the variable you saved the form to....

OR
instead of using user or admin (if they are not used in the project elsewere....) then change this to the form you want to open. and not have to go through the second if statment above.

--Todd


TechnicalUser pretending to be a programmer(shhh… the boss doesn’t know yet)
 
I have a simple form with two unbound textboxes, one for ID and the other for password. I then have a button with the following code on the On Click event: (NOTE the DLookup statements are on one line.)
(NOTE you'll notice that my logoninfo table has a prefix of Usys - Usyslogoninfo. Usys will hide the table. In this table are two fields - userid and password)

Private Sub Command5_Click()
On Error GoTo Err_Command5_Click
Dim stLinkCriteria As String
Static UserID

If IsNull(Text11 = DLookup("[Text1]", "Usyslogoninfo", "[userid] = [Text1]")) Then
MsgBox "You MUST select a valid User ID. Please try again!"
[Text1] = Null
[Text3] = Null
[Text1].SetFocus
Exit Sub
ElseIf IsNull(Text13 = DLookup("[Text3]", "Usyslogoninfo", "[password] = [Text3] And [userid] = [Text1]")) Then
MsgBox "You have entered an invalid password. Please try again!"
[Text3] = Null
[Text3].SetFocus
Exit Sub
End If

Dim stDocName As String
stDocName = "BIMMS"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "LogonForm"

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

End Sub
 
fneily is correct with the use of the dlook up there is FAQ's and other threads on this you may wish to look at, in other access topics.

Never give up never give in.
 
i have tried your code and it seems to work except for the Dlookup, it doesent give me an error, it just keeps saying "select a vid user id. please try again" is the dlookup supposed to be a table or something?? Not sure what to do from here.

Thanks great topic, great code.

"trying hard
 
I'd replace this:
If IsNull(Text11 = DLookup("[Text1]", "Usyslogoninfo", "[userid] = [Text1]")) Then
By this:
If IsNull(DLookup("userid", "Usyslogoninfo", "userid=" & [Text1])) Then
And this:
ElseIf IsNull(Text13 = DLookup("[Text3]", "Usyslogoninfo", "[password] = [Text3] And [userid] = [Text1]")) Then
By this:
ElseIf IsNull(DLookup("userid", "Usyslogoninfo", "userid=" & [Text1] & " And password='" & [Text3] & "'")) Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top