Login VBA (1 Viewer)

ria4life

Registered User.
Local time
Today, 07:14
Joined
Feb 24, 2016
Messages
40
I have this Code on a Login screen to an access database.....The Login works as expected...My only issue is i have to click on the OK button twice for the login process vs a one click.....Cant figure out whats going on...any assistance will be greatly appreciated.

------------------------------------------

Option Compare Database
Option Explicit
Public message1 As String

'ENABLE FULL DB SECURITY IF CANCEL IS CLICKED AT LOGIN
Private Sub Command0_Click()

'Dim prop As dao.Property
' Dim db As dao.Database
'On Error GoTo SetProperty
' Set prop = currentdb.CreateProperty("AllowBypassKey", dbBoolean, False)
' currentdb.Properties.Append prop
'SetProperty:
'currentdb.Properties("AllowBypassKey") = False

DoCmd.RunCommand acCmdExit
Quit acQuitSaveAll

End Sub

'*************LOGIN SCRIPT************

Private Sub Command1_Click()
Dim UserLevel As String

If IsNull(Me.txtloginid) Then
MsgBox "Please Select LoginID", vbInformation, "LoginID Required"
Me.txtloginid.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Password", vbInformation, "Password Required"
Me.txtPassword.SetFocus
Else

'***PROCESS THIS JOB IF THE LOGIN IS CORRECT*****

If (IsNull(DLookup("userlogin", "tbluser", "userlogin ='" & Me.txtloginid.Value & "'And Password = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Incorrect Password for this Login ID"
Else
UserLevel = DLookup("usersecurity", "tbluser", "userlogin = '" & Me.txtloginid.Value & "'")
PWRESET = DLookup("pwreset", "tbluser", "userlogin = '" & Me.txtloginid.Value & "'")
Forms![login].Visible = False




'***RUN THIS IF THE USER IS ADMIN****

If UserLevel = "Admin" Then
DoCmd.OpenForm "Splash_Admin"

'***Prompt option to enable/disable bypass key....takes effect after restart***

Dim prop As dao.Property
Dim db As dao.Database
On Error GoTo SetProperty
Set prop = currentdb.CreateProperty("AllowBypassKey", dbBoolean, False)
currentdb.Properties.Append prop
SetProperty:
If MsgBox("***ENABLE SECURITY BYPASS OPTION ?***", vbYesNo, "Allow Bypass?") = vbYes Then
currentdb.Properties("AllowBypassKey") = True

Else
currentdb.Properties("AllowBypassKey") = False


End If

'****RUN THIS IF THE PROFILE IS NOT ADMIN*****

Else
If UserLevel = "User" Then
DoCmd.OpenForm "Splash_User"
DoCmd.ShowToolbar "Ribbon", acToolbarNo
If Me.PWRESET = True Then
DoCmd.OpenForm "PasswordResetForm"
End If

Else
If UserLevel = "Reporting" Then
DoCmd.OpenForm "Splash_Reporting"
DoCmd.ShowToolbar "Ribbon", acToolbarNo
If Me.PWRESET = True Then
DoCmd.OpenForm "PasswordResetForm"


End If
End If
End If
End If
End If
End If


End Sub




Private Sub Form_Load()
Me.txtloginid.SetFocus
'DoCmd.ShowToolbar "Ribbon", acToolbarNo

Dim myQry As String
Dim sUserName As String
Dim sUserPC As String
' Get Current User Name
sUserName = Environ$("computername")
sUserPC = Environ$("username")
' If you want Computer Name use Environ$("computername") OR ("Username")
'myQry = "INSERT INTO tblLogUserAccess (logUser, logDate) VALUES ('" & sUserName & "',#" & Now() & "#)"
Me.CompUser = sUserName
Me.compname = sUserPC
'currentdb.Execute myQry



End Sub

Private Sub Form_Open(Cancel As Integer)
Database is restricted <--- "
'message = " Welcome To Test "
End Sub

Private Sub Form_Timer()

ownerinfo = message1
'Get first character
Dim FChar As String
FChar = Left(message1, 1)
'Remove first character
message1 = Mid$(message1, 2, Len(message1) - 1)
'Put 1st character at the end of the message.
message1 = message1 + FChar

Me.Auto_Time = Format(Time, "HH:MM:SS AM/PM")

End Sub

Private Sub txtloginid_AfterUpdate()
'GROUP = DLookup("group", "[tbluser]", "[TECH NAME]= '" & [txtloginid] & "'")
Me.txtPassword.SetFocus
End Sub

Private Sub txtloginid_Change()
Me.txtPassword = ""
End Sub

Private Sub txtPassword_AfterUpdate()
'Me.Command1.SetFocus
End Sub

Private Sub txtPassword_Exit(Cancel As Integer)
Me.Command1.SetFocus
End Sub
 
Last edited:

Cronk

Registered User.
Local time
Tomorrow, 01:14
Joined
Jul 4, 2013
Messages
2,770
If I had posted your code without indentation, I would not be surprised if nobody took the trouble to try to decipher it.

You might want to repost with indentation with the code wrap tags wrapped around it. (See the # in the format lines above the message box).
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:14
Joined
Feb 28, 2001
Messages
27,003
From your general statement of needing two clicks, I would suggest that something isn't set correctly the first time you click it. I.e. incorrect assumption of initial conditions. There is no way in Milton's Nine Levels of Hell that we would be able to find that since the problem could be in an unrelated code segment such as a Form_Load, Button_LostFocus, or some other code you haven't posted.

Set a breakpoint in the line of code that reads "If IsNull(Me.txtloginid) Then" at the beginning of your routine. Single step each line. Hover your cursor over each variable that is involved in an IF-test and see its value at that moment. When you find the place that is wrong, it should be obvious to you since YOU wrote the code and YOU know the assumptions you made. We DIDN'T write the code and DON'T know the assumptions, so for us, this method of presenting your problem sort of missed the target.
 

ria4life

Registered User.
Local time
Today, 07:14
Joined
Feb 24, 2016
Messages
40
Thanks for the initial responses....
I have attached the actual DB to this note....
Password = 123

All the code exists under the login form.....thanks in advance for your assistance
 

Attachments

  • LOGIN.accdb
    928 KB · Views: 525
Last edited:

Cronk

Registered User.
Local time
Tomorrow, 01:14
Joined
Jul 4, 2013
Messages
2,770
There might be a bit of corruption in your database. Try Compact/Repair. Then try importing all your tables/queries/forms into a blank database.
 

Users who are viewing this thread

Top Bottom