Solved

MSAccess Page Controls

Posted on 2011-09-14
7
325 Views
Last Modified: 2012-08-14
I am trying to set up controls to make the tabs (pages) on my form visable/hide based on
the security of the user.  I've got some code to copy, but I don't know how to set up the
reference to the tabs.  I understand that pages(0) refers to the first tab of the form.  What is the "TabMain" referring to?
Thanks, Lynn
Set rstRoles = db.OpenRecordset(strSQL)
        If Not rstRoles.EOF And Not rstRoles.BOF Then
            rstRoles.MoveFirst
            Do Until rstRoles.EOF
                    Select Case rstRoles.Fields("roleName")
                    Case "Processor"
                        Me.TabMain.Pages(3).Visible = True
                        Me.TabMain.Pages(4).Visible = True
                        Me.TabMain.Pages(5).Visible = True
                    Case "Security Administrator"
                        Me.TabMain.Pages(1).Visible = True
                        Me.TabMain.Pages(4).Visible = True
                        Me.TabMain.Pages(5).Visible = True
                    Case "System Administrator"
                        Me.TabMain.Pages(0).Visible = True
                        Me.TabMain.Pages(4).Visible = True
                        Me.TabMain.Pages(5).Visible = True
                    End Select
                rstRoles.MoveNext
            Loop
        End If
    Set rstRoles = Nothing
    Set db = Nothing

Open in new window

0
Comment
Question by:Lambel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 36538684
TabMain is the tab control itself, which includes the pages and tabs.
0
 

Author Comment

by:Lambel
ID: 36538735
I am still confused.  
I have a form named frmReportGenerator, with pages (tabs) named and in the following order:
Report Parameters, Recipeint-Regions, Sites-Region, Recipients, Sites, Regions, Email Message,
Users, User Roles.

To hide the last two pages (Users and User Roles), what is the correct syntax?  

I've attached a printscreen of the form for reference. printscreen-frmReportGenerator.doc printscreen-frmReportGenerator.doc
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36538936
What is the actual trouble you are having with the code you have posted?

If I'm understanding your request properly, at a minimum, you would need to also specify which pages are hidden.  Also, it looks like you would probably want your sql statement to look up the role of a particular user and then set the tabs visible or hidden ONCE, after the role has been looked up.  Your code currently has the tab visibility code inside your recordset loop.  That doesn't seem quite right.

I think you need something more like this:

dim pg as page
for each pg in me.tabmain.pages
        pg.visible = false    ' start out with all pages hidden
next

' look up the user's role
Set rstRoles = db.OpenRecordset(strSQL)
        if rstRoles.recordcount = 0 then
                msgbox "no role found for this user"
                Exit sub ' (or function)
        end if
                    Select Case rstRoles.Fields("roleName")
                    Case "Processor"
                        Me.TabMain.Pages(3).Visible = True
                        Me.TabMain.Pages(4).Visible = True
                        Me.TabMain.Pages(5).Visible = True
                    Case "Security Administrator"
                        Me.TabMain.Pages(1).Visible = True
                        Me.TabMain.Pages(4).Visible = True
                        Me.TabMain.Pages(5).Visible = True
                    Case "System Administrator"
                        Me.TabMain.Pages(0).Visible = True
                        Me.TabMain.Pages(4).Visible = True
                        Me.TabMain.Pages(5).Visible = True
                    End Select
     Set rstRoles = Nothing
    Set db = Nothing
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 61

Expert Comment

by:mbizup
ID: 36538950
The idea behind what I just posted is that the person using the database has a given 'role'.  Based on that role, you are only allowing them to see certain pages.

Is that understanding correct?
0
 

Author Comment

by:Lambel
ID: 36539258
frmReportGenerator.Pages(1).Visible = False
                        frmReportGenerator.Pages(2).Visible = False
                        frmReportGenerator.Pages(3).Visible = False
                        frmReportGenerator.Pages(4).Visible = False
                        frmReportGenerator.Pages(5).Visible = False
                        frmReportGenerator.Pages(6).Visible = False
                        frmReportGenerator.Pages(7).Visible = False
                        frmReportGenerator.Pages(8).Visible = False
0
 

Author Comment

by:Lambel
ID: 36539264
See my comments above - that syntax fixed it.  Thanks for your help
Lynn
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36539495
Glad to help out
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question