TempVar (1 Viewer)

hfsitumo2001

Member
Local time
Today, 14:39
Joined
Jan 17, 2021
Messages
365
Hello, I am gonna try like this class module on on load of each form in order to make user for Read_only on each form:
Code:
rivate Sub Form_Load()
Dim User AS String
Dim LoginType As Integer
  User = Forms (Mavigation Form)!TxtLogin
  LoginType = Dlookup("UserSecurity","TblUser","User2")
  If LoginType = 2 Then 'limited user'
    Me.AllowAdditions = Flase
    Me.AllowEdits = False
    Me.AllowDeletions = False
  End IF
End Sub

But instead of putting this code in every form, can we make it global function/module?, and in the user forms, we can just make if User Security=User2, function/module will work.

The other problem since when we login the login form will disappear and to to Navigation Menu

like this which is drill down menu. Maybe we should use TempVar? to hold the User2 from the log in form?, Any sample for this?

Thank you.

Frank
 

June7

AWF VIP
Local time
Today, 13:39
Joined
Mar 9, 2014
Messages
5,423
Should "Mavigation" be "Navigation"?

TempVar is a reasonable option to make data available after forms close. Have you done any research on their use?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:39
Joined
Feb 28, 2001
Messages
27,001
But instead of putting this code in every form, can we make it global function/module?

You can put code in a general module. However, in the context of a general module, Me.Allowxxxx=True (or false) doesn't work because Me has no referent in that case.

To make this work for every form from a single call target, do something LIKE this. (You may have to play with it...)

Code:
Public Sub SetFormSecurity( frm as Access.Form, usr as String)
Dim ulvl as Integer
...
    ulvl = DLookup( "[Level]", "[UserAcct]", "[Uname]='" & usr & "'" )
    Select Case ulvl
        Case 1
            frm.AllowEdits = False
            frm.AllowAdditions = False
        Case 2
            frm.AllowEdits = False
            frm.AllowAdditions = True
      ....
    End Select
Exit Sub

Then in each form-load event include

Code:
    SetFormSecurity Me, Forms!NavigationForm!txtLogin

Remember that Me.x has meaning ONLY in the context of the class module associated with the form. In a general form you must pass in the form reference, such as the way I demonstrated here.
 

hfsitumo2001

Member
Local time
Today, 14:39
Joined
Jan 17, 2021
Messages
365
You can put code in a general module. However, in the context of a general module, Me.Allowxxxx=True (or false) doesn't work because Me has no referent in that case.

To make this work for every form from a single call target, do something LIKE this. (You may have to play with it...)

Code:
Public Sub SetFormSecurity( frm as Access.Form, usr as String)
Dim ulvl as Integer
...
    ulvl = DLookup( "[Level]", "[UserAcct]", "[Uname]='" & usr & "'" )
    Select Case ulvl
        Case 1
            frm.AllowEdits = False
            frm.AllowAdditions = False
        Case 2
            frm.AllowEdits = False
            frm.AllowAdditions = True
      ....
    End Select
Exit Sub

Then in each form-load event include

Code:
    SetFormSecurity Me, Forms!NavigationForm!txtLogin

Remember that Me.x has meaning ONLY in the context of the class module associated with the form. In a general form you must pass in the form reference, such as the way I demonstrated here.
Thank you Sir, I will try to figure it out.

Frank
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:39
Joined
Feb 19, 2002
Messages
42,976
One point to ponder. Setting AllowEdits to No also disables the use of unbound combos for searching. If that is a problem for you, I have other suggestions.
 

hfsitumo2001

Member
Local time
Today, 14:39
Joined
Jan 17, 2021
Messages
365
One point to ponder. Setting AllowEdits to No also disables the use of unbound combos for searching. If that is a problem for you, I have other suggestions.
Could you let me know your suggestion Pat Hartman?. My main purpose is to just let the user to read-only/just to view for all user forms, except for report they can just print it.

Thank you

Frank
 

hfsitumo2001

Member
Local time
Today, 14:39
Joined
Jan 17, 2021
Messages
365
You can put code in a general module. However, in the context of a general module, Me.Allowxxxx=True (or false) doesn't work because Me has no referent in that case.

To make this work for every form from a single call target, do something LIKE this. (You may have to play with it...)

Code:
Public Sub SetFormSecurity( frm as Access.Form, usr as String)
Dim ulvl as Integer
...
    ulvl = DLookup( "[Level]", "[UserAcct]", "[Uname]='" & usr & "'" )
    Select Case ulvl
        Case 1
            frm.AllowEdits = False
            frm.AllowAdditions = False
        Case 2
            frm.AllowEdits = False
            frm.AllowAdditions = True
      ....
    End Select
Exit Sub

Then in each form-load event include

Code:
    SetFormSecurity Me, Forms!NavigationForm!txtLogin

Remember that Me.x has meaning ONLY in the context of the class module associated with the form. In a general form you must pass in the form reference, such as the way I demonstrated here.
The doc_Man, this code: SetFormSecurity Me, Forms!LoginForm!txtLogin, can work if my login form is always open right?. When the login successful, the form will automatically close and go to navigation(Switchboard) which is a drilldown menu like this:
Navigation_doc.jpg
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:39
Joined
Feb 28, 2001
Messages
27,001
If the form is open, then a Form!form-name!field-name reference is legal.

There are many ways to "skin this cat" and leaving the login form open is one way. If you want other ways to do this that don't involve keeping a form open for such a long time, ask away.
 

hfsitumo2001

Member
Local time
Today, 14:39
Joined
Jan 17, 2021
Messages
365
There are many ways to "skin this cat" and leaving the login form open is one way. If you want other ways to do this that don't involve keeping a form open for such a long time, ask away.
Is that using TempVars is another way to keep the login value in memory?, but I do not have the sample to learn. Do you have it?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:39
Joined
Feb 19, 2002
Messages
42,976
Personally, I prefer to leave the log in form open and hidden but that goes back to the days before Tempvars. I still do it today because, I also have security settings on the login form because I bind it to a table/query. During testing, I can unhide the login form so I can change various settings without having to login as a different person. You can do the same thing with TempVars but you can't "see" all the Tempvars in one place the way you can with a form.

Regarding the problem caused by setting AllowEdits to No. I just don't do it. I leave the form editable so that the search controls and navigation controls continue to work and I "trap" the edit by putting code in the form's on Dirty event. The Dirty event fires as soon as a user types a single character in the form. Your code would then check the authorization level and if the user is not authorized to edit the data, you would Cancel the event and Undo the edit and give the user an error message.
Code:
If Forms!frmLogin!AllowEdits = True Then
Else
    Cancel = True
    Me.Undo
    Exit Sub
End If
 

hfsitumo2001

Member
Local time
Today, 14:39
Joined
Jan 17, 2021
Messages
365
Personally, I prefer to leave the log in form open and hidden but that goes back to the days before Tempvars. I still do it today because, I also have security settings on the login form because I bind it to a table/query. During testing, I can unhide the login form so I can change various settings without having to login as a different person. You can do the same thing with TempVars but you can't "see" all the Tempvars in one place the way you can with a form.

Regarding the problem caused by setting AllowEdits to No. I just don't do it. I leave the form editable so that the search controls and navigation controls continue to work and I "trap" the edit by putting code in the form's on Dirty event. The Dirty event fires as soon as a user types a single character in the form. Your code would then check the authorization level and if the user is not authorized to edit the data, you would Cancel the event and Undo the edit and give the user an error message.
Code:
If Forms!frmLogin!AllowEdits = True Then
Else
    Cancel = True
    Me.Undo
    Exit Sub
End If
Thank you Pat, I will try to think what is the best method for my database design.
 

Users who are viewing this thread

Top Bottom