JohnMichael72
Gold Supporter
- Local time
- Today, 15:46
- Joined
- Jul 25, 2019
- Messages
- 11
Hello All,
I am in desperate need of some assistance with modifying some code in VB. I created a database for work some time ago that has VB code written that requires the user to log in. Once they log in, depending upon the security level assigned to that user, they are taken to one of three forms. The database worked perfectly until it was decided to convert the Primary Keys in the tables to GUID's. Now, I need to modify the VB code on the login form so that it can handle the use of GUID's. The issue is coming from the section of the code that directs the user to the correct form when logging in.
The code for the original database that uses an Integer as the primary Key:
The Admin UserLevel GUID is BE698569-F315-472E-B0E6-814A51B73707
The SuperAdmin UserLevel GUID is D3A01D69-5BF1-4D44-9780-C8ACB033184A
The issue is coming from the "open a different form according to user level" part. I no longer use the 1 or 3 to define the user levels because it is now a GUID. I am thinking it has something to do with needing to convert it to a string or something along those lines. Any help would be immensely appreciated!!
JM
I am in desperate need of some assistance with modifying some code in VB. I created a database for work some time ago that has VB code written that requires the user to log in. Once they log in, depending upon the security level assigned to that user, they are taken to one of three forms. The database worked perfectly until it was decided to convert the Primary Keys in the tables to GUID's. Now, I need to modify the VB code on the login form so that it can handle the use of GUID's. The issue is coming from the section of the code that directs the user to the correct form when logging in.
The code for the original database that uses an Integer as the primary Key:
Code:
Private Sub Command1_Click()
Dim UserName, Temppass As String
Dim UserLevel, ID As Integer
Dim TempLogin As TempVar
If IsNull(Me.txtLoginID) Then
MsgBox "Please enter UserID", vbInformation, "UserID requeired"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Password", vbInformation, "Password requeired"
Me.txtPassword.SetFocus
Else
If (IsNull(DLookup("UserID", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "' And password = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid LoginID or Password!"
Else
TempVars!TempLogin = Me.txtLoginID.Value
UserName = DLookup("[Username]", "tblUser", "[UserLogin] = '" & Me.txtLoginID.Value & "'")
UserLevel = DLookup("[UserSecurity]", "tbluser", "[UserLogin] = '" & Me.txtLoginID.Value & "'")
Temppass = DLookup("[password]", "tblUser", "[UserLogin] = '" & Me.txtLoginID.Value & "'")
ID = DLookup("[Userid]", "tblUser", "[UserLogin] = '" & Me.txtLoginID.Value & "'")
'DoCmd.Close
If (Temppass = "password") Then
DoCmd.Close
MsgBox "Please change Password", vbInformation, "New password requeired"
DoCmd.OpenForm "ChangePassword", , , "[Userid] = " & ID
ElseIf IsNull(DLookup("answer1", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "'")) Or IsNull(DLookup("answer2", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "'")) Or IsNull(DLookup("answer3", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "'")) Then
DoCmd.Close
msg = "Your security questions have not been set up. " _
& vbCr & "Do you want to set it up now?"
Style = vbYesNo + vbQuestion
Title = "Set Up Security Question?"
Response = MsgBox(msg, Style, Title)
If Response = vbYes Then
DoCmd.OpenForm "ChangePassword", , , "UserID =" & ID
Exit Sub
End If
If Response = vbNo Then
'open different form according to user level
If UserLevel = 3 Then ' for superadmin
DoCmd.ShowToolbar "Ribbon", acToolbarYes
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.SelectObject acTable, , True
DoCmd.OpenForm "Super Admin Form"
ElseIf UserLevel = 1 Then ' for admin
DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
DoCmd.OpenForm "Admin Form"
Else
DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
DoCmd.OpenForm "Main Form"
End If
End If
Else
DoCmd.Close
'open different form according to user level
If UserLevel = 3 Then ' for superadmin
DoCmd.ShowToolbar "Ribbon", acToolbarYes
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.SelectObject acTable, , True
DoCmd.OpenForm "Super Admin Form"
ElseIf UserLevel = 1 Then ' for admin
DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
DoCmd.OpenForm "Admin Form"
Else
DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
DoCmd.OpenForm "Main Form"
End If
End If
End If
End If
End Sub
The Admin UserLevel GUID is BE698569-F315-472E-B0E6-814A51B73707
The SuperAdmin UserLevel GUID is D3A01D69-5BF1-4D44-9780-C8ACB033184A
The issue is coming from the "open a different form according to user level" part. I no longer use the 1 or 3 to define the user levels because it is now a GUID. I am thinking it has something to do with needing to convert it to a string or something along those lines. Any help would be immensely appreciated!!
JM
Last edited: