[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-02-18
5
Medium Priority
?
336 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 120

Accepted Solution

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

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

830 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