Solved

Procedure to Make Button Visible and Place on Screen based on variable

Posted on 2011-02-18
5
321 Views
Last Modified: 2012-05-11
I've designed a form with a number of buttons.  I need to make the button visible based on a user's security level.  I'm in the process of building the code that makes the buttons visible and places then on the screen:

If rs![FunctionName] = "Contact Management" Then
    Me.btnContactManagement.Visible = True
    Me.lblContactManagement.Visible = True
    Me.btnContactManagement.Left = 1440 * sLeftMargin
    Me.lblContactManagement.Left = 1440 * (sLeftMargin + 0.25)
    Me.btnContactManagement.Top = 1440 * sTopMargin
    Me.lblContactManagement.Top = 1440 * (sTopMargin + 0.25)
    sTopMargin = sTopMargin + 0.3
End if

Since I've consistently named the buttons and their lables, is there a way to build this in a procedure, such as:

If rs![FunctionName] = "Contact Management" Then
    Call Setup_Buttons("ContactManagement",sLeftMargin,sTopMargin)
End if

I guess the procedure would look something like this:

Private Sub Setup_Buttons(strObjectName As String, sLeft As Single, sTop As Single)

'Make sure you don't re-place button if it is already visible.
If Me."btn" & strObjectName.Visible = False
    Me."btn" & strObjectName.Visible = True
    Me."lbl" & strObjectName.Visible = True
    Me."btn" & strObjectName.Left = 1440 * sLeft
    Me."lbl" & strObjectName.Left = 1440 * (sLeft + 0.25)
    Me."btn" & strObjectName.Top = 1440 * sTop
    Me."lbl" & strObjectName.Top = 1440 * (sTop + 0.25)
    sTopMargin = sTopMargin + 0.3
End if
End Sub

Perhaps there's a function that I need to incorporate to enable me to work with the buttons and labels through variables.  Thanks in advance for your assistance, and let me know if you need any further clarification.
0
Comment
Question by:dhjensen
  • 3
  • 2
5 Comments
 

Author Comment

by:dhjensen
ID: 34930364
For what it's worth, I just discovered that apparently "sTop" is a MS Access reserve word.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 34930372
use this format


Private Sub Setup_Buttons(strObjectName As String, sLeft As Single, sTop As Single)

'Make sure you don't re-place button if it is already visible.
If Me("btn" & strObjectName).Visible = False then
    Me("btn" & strObjectName).Visible = True
    Me("lbl" & strObjectName).Visible = True
    Me("btn" & strObjectName).Left = 1440 * sLeft
    Me("lbl" & strObjectName).Left = 1440 * (sLeft + 0.25)
    Me("btn" & strObjectName).Top = 1440 * sTop
    Me("lbl" & strObjectName).Top = 1440 * (sTop + 0.25)
    sTopMargin = sTopMargin + 0.3
End if
End Sub

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34930379
oh yes, it means Stop > halt the codes


Private Sub Setup_Buttons(strObjectName As String, sLeft As Single, vTop As Single)

'Make sure you don't re-place button if it is already visible.
If Me("btn" & strObjectName).Visible = False then
    Me("btn" & strObjectName).Visible = True
    Me("lbl" & strObjectName).Visible = True
    Me("btn" & strObjectName).Left = 1440 * sLeft
    Me("lbl" & strObjectName).Left = 1440 * (sLeft + 0.25)
    Me("btn" & strObjectName).Top = 1440 * vTop
    Me("lbl" & strObjectName).Top = 1440 * (vTop + 0.25)
    vTopMargin = vTopMargin + 0.3
End if
End Sub

Open in new window

0
 

Author Comment

by:dhjensen
ID: 34930440
Thanks--seting it up now....
0
 

Author Closing Comment

by:dhjensen
ID: 34930627
Thanks very much--it works great!  Perfect solution!  (And I'll stay away from the Stop reserve word.)  Have a great weekend....
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

744 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

14 Experts available now in Live!

Get 1:1 Help Now