Solved

MSAccess Page Controls

Posted on 2011-09-14
7
284 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
Comment Utility
TabMain is the tab control itself, which includes the pages and tabs.
0
 

Author Comment

by:Lambel
Comment Utility
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
Comment Utility
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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 61

Expert Comment

by:mbizup
Comment Utility
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
Comment Utility
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
Comment Utility
See my comments above - that syntax fixed it.  Thanks for your help
Lynn
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Glad to help out
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

772 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

11 Experts available now in Live!

Get 1:1 Help Now