By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,489 Members | 1,932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,489 IT Pros & Developers. It's quick & easy.

variable field

P: 36
Hi all,

How can I store field name into a variable and then access its properties?

for example field text1

I'm trying something like this

dim box as string
box = "text1"
box.visible = true


I always get error
I even tried [box].visible and ["box"].visible but non works

thanks
Dec 23 '06 #1
Share this Question
Share on Google+
6 Replies


100+
P: 1,646
Hi all,

How can I store field name into a variable and then access its properties?

for example field text1

I'm trying something like this

dim box as string
box = "text1"
box.visible = true


I always get error
I even tried [box].visible and ["box"].visible but non works

thanks
Hi. Nice try. The question is where do you want it to be visible?
If it is on a form in a label or textbox you will need to put one on your form and then reference it in your code.

Expand|Select|Wrap|Line Numbers
  1. textbox1.text = "text 1"
good luck
Dec 23 '06 #2

ADezii
Expert 5K+
P: 8,597
Hi all,

How can I store field name into a variable and then access its properties?

for example field text1

I'm trying something like this

dim box as string
box = "text1"
box.visible = true


I always get error
I even tried [box].visible and ["box"].visible but non works
thanks
'Your syntax is incorrect, this will work:
Expand|Select|Wrap|Line Numbers
  1. Dim T As TextBox
  2.  
  3. Set T = Me![txtText]
  4. T.Visible = False
Dec 23 '06 #3

P: 36
'Your syntax is incorrect, this will work:
Expand|Select|Wrap|Line Numbers
  1. Dim T As TextBox
  2.  
  3. Set T = Me![txtText]
  4. T.Visible = False
Thanks for everybody replies
Here is what I'm really trying to do

in a form there is option button 4 and option button 6
there are also 2 hidden text fields: text0 and text2
and a button

I want when ever an option button is checked and the button clicked then one of the textboxes would become visible depending which one is still invisible

so for example checking option button 4 would turn text0 visible coz its the first textbox that is invisible, then checking option button 6 would turn text2 visible unless text0 is still invisible (option 4 hasn;t been checked) then it would turn text0 visible.

checking any option button off would turn its corresponding textbox invisible when you click the button

this is my code that sucks, doesn't work


Private Sub Command10_Click()
Dim box As TextBox

Set box = findbox()

If Option4.Value = -1 Then
Dim option4box As TextBox
Set option4box = Me![box]
option4box.Visible = True
Else
Set option4box.Visible = False
End If

If Option6.Value = -1 Then
Dim option6box As TextBox
Set option6box = Me![box]
option6box.Visible = True
Else
Set option6box.Visible = False
End If

End Sub
-----------------------------------------------
Public Function findbox() As TextBox
If Text0.Visible = False Then
Set findbox = Me![Text0]
ElseIf Text2.Visible = False Then
Set findbox = Me![Text2]
Else
MsgBox "all boxes has been used"
End If
End Function
Dec 24 '06 #4

100+
P: 1,646
Ok it is not nearly this difficult.

Expand|Select|Wrap|Line Numbers
  1. If Option4.Value Then
  2.    Text0.Visible = True
  3.    Text2.Visible = False
  4. Else
  5.    Text0.Visible = False
  6.    Text2.Visible = True
  7. End If
Dec 24 '06 #5

100+
P: 1,646
BTW this code should be in the click event of your option frame. No need for a button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Frame1_Click()
  2.     If Frame1.Value = -1 Then
  3.         Text0.Visible = True
  4.         Text2.Visible = False
  5.     Else
  6.         Text0.Visible = False
  7.         Text2.Visible = True
  8.     End If
  9. End Sub
Dec 24 '06 #6

NeoPa
Expert Mod 15k+
P: 31,186
Try this :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Frame1_Click()
  2.     Text0.Visible = Me.Frame1
  3.     Text2.Visible = Not Me.Frame1
  4. End Sub
Dec 28 '06 #7

Post your reply

Sign in to post your reply or Sign up for a free account.