Solved

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

Posted on 2011-02-18
5
324 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

948 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

22 Experts available now in Live!

Get 1:1 Help Now