Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to dynamically build a VBA command?

Status
Not open for further replies.

RansomEli

Programmer
Jul 27, 2005
4
US
Relatively new to Access 2007 and VBA programming. Hope this question makes sense.

I have a form display. I have a set of 10 labels that are column headers, labeled as Label1, Label2, etc. Depending on user inputs, I only want to display a subset of the labels.

What I would like to do is, if the user types in a 5, make Labels 1-5 visible and labels 6-10 invisible.

How can I use VBA to dynamically build a command like:

for x= 1 to 10
if x <= 5 then
value = "true"
else
value = "false"

string x = "Label" & x & ".Visible = " & value
ExecuteVBACommand x

Thanks in advance for any help.I hope this makes sense.
 
If I understand correctly, you might be able to use something like:

Code:
Dim intI as Integer
Dim intN as Integer
'you might want to add some error handling code for PEBKAC
intN = InputBox("Enter a number from 1 to 10")
For intI = 1 to 10
   Me("Label" & intI).Visible = (intI <=intN)
Next


Duane
Hook'D on Access
MS Access MVP
 
You might find some techniques of use here faq702-5010

It might look something like this:

[tt]For x = 1 to 10
Me.Controls("Label" & x).Visible = (x <= TheInputtedNumber)
Next x[/tt]

Roy-Vidar
 
Thanks to both answers. I knew it had to be simple.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top