Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MSAccess Page Controls

Posted on 2011-09-14
7
Medium Priority
?
347 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 2000 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

963 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