Disable Editing Subform in navigation form (1 Viewer)

alvingenius

IT Specialist
Local time
Today, 06:39
Joined
Jul 10, 2016
Messages
169
there is a code for it. better to put the code in the Load event of the nav form,
becoz right's of each user will likely not change, so using current event you always enable/disable the control.
Code:
Dim bolJumped as Boolean
If txtaccesstab1= False Then ' from dlookup 
    Forms!frmMain!Nav1.Enabled = False
Else
    Forms!frmMain!Nav1.Enabled = True
    If bolJumped = False Then
       bolJumpted = True
       Forms!frmMain!Nav1.Setfocus
       Sendkeys "{ENTER}"
    End If
End If

If txtaccesstab2= False Then ' from dlookup 
    Forms!frmMain!Nav2.Enabled = False
Else
    Forms!frmMain!Nav2.Enabled = True
    If bolJumped = False Then
       bolJumpted = True
       Forms!frmMain!Nav2.Setfocus
       Sendkeys "{ENTER}
    End If
End If

If txtaccesstab3= False Then ' from dlookup 
    Forms!frmMain!Nav3.Enabled = False
Else
    Forms!frmMain!Nav3.Enabled = True
    If bolJumped = False Then
       bolJumpted = True
       Forms!frmMain!Nav3.Setfocus
       Sendkeys "{ENTER}"
    End If
End If

Well, that's worked like charm :D:D

Thanks alot @arnelgp and thanks to @theDBguy
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:39
Joined
Oct 29, 2018
Messages
21,447
Well, that's worked like charm :D:D

Thanks alot @arnelgp and thanks to @theDBguy

Hi. Glad to hear you got it sorted out. Good luck with your project.
 

jepoysaipan

Registered User.
Local time
Today, 14:39
Joined
Nov 4, 2007
Messages
133
Hi,

I am now having the same problem, on my Navigation Form when a user clicked a button it automatically shows the "subform" associated with "Navigation Target Name", now I wanted to disable this "subform" based on User Roles, others tab are ok to play with are there any solutions to this one? Thanks in advance!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:39
Joined
May 7, 2009
Messages
19,226
initially set the tab's navigationTargetName = ""
and set it (on click event) based on who is the user.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:39
Joined
Feb 19, 2002
Messages
43,196
I think you're all making this harder than it needs to be. It doesn't matter whether or not the subform is locked. All that matters is that you stop an update by an unauthorized user. Therefore, in the subform's on Dirty event, check the credentials of the user. If he is not authorized, undo the the update to the record and give the user an error message.
 

jepoysaipan

Registered User.
Local time
Today, 14:39
Joined
Nov 4, 2007
Messages
133
initially set the tab's navigationTargetName = ""
and set it (on click event) based on who is the user.
Hi Arnelgp,

I tried your approach but doesn't seem to get the job done, it will work initially when the logged user is not allowed to view the "subform" under the navigation tab, but when an allowed user is the active one, I need to click that navigation tab to show the "subform", what I need is when a trusted user is logged the default behavior of the Navigation should be as is and changes only whenever an unauthorized user is currently logged-in.

Hope it make sense :)
 

jepoysaipan

Registered User.
Local time
Today, 14:39
Joined
Nov 4, 2007
Messages
133
I think you're all making this harder than it needs to be. It doesn't matter whether or not the subform is locked. All that matters is that you stop an update by an unauthorized user. Therefore, in the subform's on Dirty event, check the credentials of the user. If he is not authorized, undo the the update to the record and give the user an error message.
Hi Pat,

I got your point on this, but what I am trying to accomplish is what my professor in PROG/SAD class always taught us "never give/show an option to an unauthorized user in your program/application..." for there will be more questions/explanations involved plus it is not a good practice to let them spend their time filling-up something that they are not allowed to save in the end.

I am looking on a solution to prevent the above so during the "On Load" or an "On Click" event of the main Navigation is what I am targetting, but still no luck :(
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:39
Joined
May 7, 2009
Messages
19,226
here is a simple demo.

enter user "a" and password 1.
if you go to the "tab 1", there won't be any subform.

close and re-open the navigation form.

enter user "b" and password 2.
goto tab 1. chan-charan!

** see the code-behind the tab button.
 

Attachments

  • login_navigation.accdb
    992 KB · Views: 56

jepoysaipan

Registered User.
Local time
Today, 14:39
Joined
Nov 4, 2007
Messages
133
Thanks Arnel, it works logically on a single nav, but below is the screenshot of my form (Horiz & Vert Left Nav) the problem I am facing is I want the "Add New Product" and "Edit Product" either be disabled or hidden including the "subforms" so the user can only navigate/click the "View Products" otherwise if they are a trusted user all nav buttons & "subforms" are enabled.

I cant seem to trap the nav button event, by default when a user clicked the "Products" menu it opens up the "Add New Product" and display the underlying subform, what I am trying to do is to trap the event based on user level when clicking a nav. buttons on the left side (parent).

1637753468019.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:39
Joined
May 7, 2009
Messages
19,226
i tried to mimic your 2 navigation form.
same demo try user "a" (pwd=1) first.

close and re-open the "navigation form 1"
user "b" (pwd=2).

another... "chan-charan!"
 

Attachments

  • login_navigation.accdb
    1.2 MB · Views: 59

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:39
Joined
Feb 19, 2002
Messages
43,196
"never give/show an option to an unauthorized user in your program/application..."
Whatever that application was, it wasn't Access and it didn't use bound forms. In my COBOL days, I practiced the same advice. Using the method I suggested, you are stopping the user as soon as he types a SINGLE character. Normal validation on bound forms is done in the form's BeforeUpdate event but that event is the last one to run before a record is saved and you absolutely do not want the user to get that far before you stop him since you are not going to let him save. So, you stop him in the FIRST event.

An Access navigation form is especially problematic for the method you are attempting. Only ONE subform is ever loaded at one time. That means that you CANNOT set the forms all at one time. You have to set them when they gain focus. Even if you were to write code to cycle thorugh them once when the main form opens, the effect would be lost the next time the user presses the tab so the code needs to work ONLY on the current form whatever method you choose.

If you want to stick with a navigation form, you should build your own. You can make it look like the Access version but you will have much more control over locking/hiding options. I don't ever use the Access navigation form because it does what it does the way it wants to do it which is a problem when I want to customize actions.

Access is a RAD (Rapid Application Development) tool. You will have far fewer problems once you understand how form events work and what each is for.
 
Last edited:

jepoysaipan

Registered User.
Local time
Today, 14:39
Joined
Nov 4, 2007
Messages
133
Hey Pat,

Nice to see a fellow COBOL programmer on this thread, I started as COBOL/CICS Programmer way back on Mid/Mainframes lolz.

Anyways, @arnelgp got the drift of what I am tackling and it works as I envisioned!

Thanks for your insights and as always "we" as programmers can always find a way to circumvent and/or find a work around on something...

Cheers!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:39
Joined
Feb 19, 2002
Messages
43,196
You can write a couple of lines of code or dozens. Your choice. I've written my million lines of code and so don't need the practice.. I'd rather take advantage of form events and use them to serve me:)
 

Users who are viewing this thread

Top Bottom