Why do you refuse to post code between CODE tags in spite of having been previously asked to do so?
I had checked a couple of hours ago but could find no posts by this OP with keywords "code tags" so here it is cleaned up and posted with tags this one time but not proof read by me. NOTE: code tags are added via # button on posting toolbar.
The fact that the prior sub is now a function hasn't changed anything - it still does the same as before, which is nothing. I think OP is copying code from other sources with pretty much zero idea of what it does. It's OK; we all had to start somewhere but maybe some research into subs and functions would be a good idea first. Kind of like learning to crawl before trying to run a marathon.
Code:
Option Compare Database
Option Explicit
Public Function GetUserName() As String
Dim User As String, Username As String, Name As String
Name = Username
End Function
'Then, in the btnLogin_Click event is the following code (much of this has been commented out currently)
Private Sub btnLogin_Click()
' Look into adding new tblDevelopers and add new if statement If rs.NoMatch to look at tblDevelopers to see if a match is found.
Dim rs As Recordset
Dim db As Database
Me.txtUserName.SetFocus
Set db = CurrentDb
Set rs = db.OpenRecordset("tblUsers", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.txtUserName & "'"
If rs.NoMatch = True Then
Me.lblWrongUser.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblWrongUser.Visible = False
If rs!UserPassword <> Nz(Me.txtPassword) Then
Me.lblWrongPassword.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblWrongPassword.Visible = False
If rs!UserType = 4 Then 'Checks to what user Priviledges User Has Developer Priviledges
Dim prop As Property
Call GetUserName
User = txtUserName
On Error GoTo SetProperty
Set prop = CurrentDb.CreateProperty("AllowByPassKey", dbBoolean, False)
CurrentDb.Properties.Append prop
SetProperty:
If MsgBox("Would you like to turn on the bypass key?", vbYesNo, "Allow Bypass") = vbYes Then
CurrentDb.Properties("AllowBypassKey") = True
Else
CurrentDb.Properties("AllowBypassKey") = False
End If
End If
DoCmd.OpenForm "frmNorthPointMain"
DoCmd.Close acForm, "frmLoginScreen"
If rs!UserType = 1 Then 'Checks to what user Priviledges User Has, opens frmNavigation
DoCmd.Close acForm, "frmNorthPointMain"
User = txtUserName
DoCmd.Close acForm, "frmLoginScreen"
End If
If rs!UserType = 2 Then 'Checks to what user Priviledges User Has, opens frmNavDataEntry
CurrentDb.Properties("AllowBypassKey") = False
DoCmd.OpenForm "frmNorthPointMain"
User = txtUserName
DoCmd.Close acForm, "frmLoginScreen"
End If
If rs!UserType = 3 Then 'Checks to what user Priviledges User Has, opens frmNavusers
CurrentDb.Properties("AllowBypassKey") = False
DoCmd.Close acForm, "frmNorthPointMain"
User = txtUserName
DoCmd.Close acForm, "frmLoginScreen"
End If
If rs!UserType = 5 Then 'Checks to what user Priviledges User Has, opens frmLabels-Users
CurrentDb.Properties("AllowBypassKey") = False
DoCmd.Close acForm, "frmNorthPointMain"
User = txtUserName
DoCmd.Close acForm, "frmLoginScreen"
End If
If rs!UserType = 7 Then 'Checks to what user Priviledges User Has, opens frmLabels-Users
CurrentDb.Properties("AllowBypassKey") = True
DoCmd.OpenForm "frmNorthPointMain"
DoCmd.OpenForm "frmAssetTruck"
DoCmd.OpenForm "frmEmployees"
User = txtUserName
DoCmd.Close acForm, "frmLoginScreen"
End If
End Sub