Solved

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

Posted on 2011-02-18
5
332 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
[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
  • 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

688 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