Solved

MSAccess Page Controls

Posted on 2011-09-14
7
296 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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now