A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

use variable in expression?



 
 
Thread Tools Display Modes
  #1  
Old October 5th, 2006, 09:05 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 3
Default use variable in expression?

I have a form with a map of the US as a background and an image of a
star on each state. I want to change the visibility property of each
image when a transparent button is clicked that's over each state (I'll
need to do other things as well, but this is a start).
But it seems that I can't use a variable in the expression to change
this property, along the lines of:

'(Where strState is the name of the image)
Me.strState.Visible = True

I tried writing a simple wrapper based on a suggestion I saw elsewhere
in this forum:

Public Function state(strState As String)
state = strState
End Function

And using this instead:

Me.state(strState).Visible = True

It's clear that what I'm doing is wrong on some fundamental level, but
I wonder if there actually is some way to achieve this (short of
writing the expression out 50 times).

  #2  
Old October 5th, 2006, 09:45 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 3
Default use variable in expression?

Kind of surprised by my own stupidity here. After a few more minutes
of fiddling, I figured it out:

total = Me.Controls.Count
total = total - 1
For i = 0 To total
individual = Me.Controls.Item(i).Name
If individual = strState Then
If Me.Controls.Item(i).Visible = False Then
Me.Controls.Item(i).Visible = True
Else
Me.Controls.Item(i).Visible = False
End If
End If
Next

wrote:
I have a form with a map of the US as a background and an image of a
star on each state. I want to change the visibility property of each
image when a transparent button is clicked that's over each state (I'll
need to do other things as well, but this is a start).
But it seems that I can't use a variable in the expression to change
this property, along the lines of:

'(Where strState is the name of the image)
Me.strState.Visible = True

I tried writing a simple wrapper based on a suggestion I saw elsewhere
in this forum:

Public Function state(strState As String)
state = strState
End Function

And using this instead:

Me.state(strState).Visible = True

It's clear that what I'm doing is wrong on some fundamental level, but
I wonder if there actually is some way to achieve this (short of
writing the expression out 50 times).


  #3  
Old October 5th, 2006, 09:52 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default use variable in expression?

Me.Controls(strState).Visible = True


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


wrote in message
ups.com...
I have a form with a map of the US as a background and an image of a
star on each state. I want to change the visibility property of each
image when a transparent button is clicked that's over each state (I'll
need to do other things as well, but this is a start).
But it seems that I can't use a variable in the expression to change
this property, along the lines of:

'(Where strState is the name of the image)
Me.strState.Visible = True

I tried writing a simple wrapper based on a suggestion I saw elsewhere
in this forum:

Public Function state(strState As String)
state = strState
End Function

And using this instead:

Me.state(strState).Visible = True

It's clear that what I'm doing is wrong on some fundamental level, but
I wonder if there actually is some way to achieve this (short of
writing the expression out 50 times).



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:30 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.