Why not just use Value? I think that should do; no need to sometimes select Text and sometimes Value, since these are unbound controls.
Main Topics
Browse All TopicsI have a form with unbound textboxes and comboboxes.
I want to create a function where I can alternate between two properties.
The two properties are "text" and "value"
I thought this was the theory
Forms("formname").Controls
and thus in a short form the below should work.
dim valuetype as string
valuetype = "Value"
Me.txt_date.Properties(val
I get invalid reference to the property value - 2455
Could someone point me in the right direction please.
Why do I get that this is an invalid reference to the property value 2455
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Text boxes don't have a property called "valuetype".
Try
dim valuetype as string
valuetype = "Value"
Me.txt_date = valuetype
Will enter the word value in the text box.
Not sure what you are trying to achieve here but if it's what I think you are trying to do, then you are trying to specify that the text box should contain either a string value or a number value. If this is the case, then you can't. The data type of the text box is determined by the Field Type in the underlying control source table.
You can change how the text box displays the data ie "Long Date, Short Date, Currency etc" But it is the table that determines the data type.
Hope this helps
Leigh
Sorry if the control source of txt_date is in fact a date field in the underlying table as the name suggests then the code I posted will produce an error. ie The value you entered is not valid for this field.
Wont Work !
dim valuetype as string
valuetype = "Value"
Me.txt_date = valuetype
Should work
dim valuetype as Date
valuetype = #1/1/2009#
Me.txt_date = valuetype
Should enter the date 1/1/2009 in the field
Leigh
ldunscombe I am not sure you understand what I am attempting here.
Hi Helen, for unbound controls I believe I must use the .text property because I am checking the contents of the control with the . Onchange event. For this . Value does not update till the control loses focus. But then later when all controls are filled I want to use .value cause .Text only works if the control has focus
<ldunscombe I am note sure where you get date again.>
I am really, really confused now. your question specified "Me.txt_date.Properties(va
it's the name of your control "txt_date" is where I got date from. You also have made no reference to a function or exactly what you are trying to achieve. I am trying to help with "Best Guesses" from the information you have provided. If you can be more clear about what you are trying to do I am "Certain" that myself or another contributor to this site will be able to help you out.
The quality of the answers you get will be proportional to the quality of the problem description you provide.
Leigh.
Me.txt_date.Properties(val
Thanks Leigh
So you know how you use something like this
Form - Control - Property
Me.mytextboxname.t
Well what I want to do is I want to be more flexible with this.
For example the below example means that I can set "str_FormName" to ANY form I have with that textbox and I can use the one line many many times. I can then throw this in a function and the function could be used for all my forms.
Form - Control - Property
Forms(str_FormName
So now I want to be able to do the same thing but with the PROPERTY
Me.mytextboxname.?
I
I still don't understand
If you are passing it to a function then as you know the valuue you pass is subject to the event you call it from.
for example if you are calling a function from the on change event of the control itself you would use something like
MyFunction(me.textboxname.
or
if calling from any other event or another control
MyFunction(me.textboxname)
????
Leigh
I did not realise my question was so hard.
I agree I could pass the whole control to the function but that would not work as the function has many controls in it.
I was trying to keep this on a semi theoretical level but I think you are dying to see the function, so an example is below. The below is a start BUT IS NOT FINISHED in other ways other than this question.
Once again the form has all UNBOUND controls.
I want to update another section of the form with every change to a control.
Thus as far as I know I must use .text for this.
Also the control must have focus - thus the test with the IF for the control with focus. (this will have to be changed if we do get Value to work here as well)
Thus .text cannot be used to check all the controls so then I want to use value.
I am tending towards not worrying about it and just creating two functions.
Now I think I know where your going,
Your function is referring to the active control so all you need to do is check if it is bound or unbound.
ie
Dim mycontrol As Control
Set mycontrol = Screen.activecontrol
if len(mycontrol.controlsourc
' The control is unbound and you need to use the text property.
else
' The control is a bound control. use the value property
end if
Are we getting close ???
Leigh
You are right there are probably 1000 ways to write my function for testing what is in each control. But that is not the question. In fact your last suggestion (which is a good one) avoids the question. :-)
The question is how to use a variable in the place of the Property Name of a control.
I know how to do this and use it quite often for Forms and Control Names but until now have not been successful with the PROPERTY NAME.
Just so we are aware of the subtle but distinctive difference, open a form myForm with a text box tbxLName, bound to a table Names. The text box should now be displaying the last name of the first record - say Smith. Now, click on the textbox, and change just the last letter to 't' - Smitt - now type Alt+F11 and in the Immediate pane type:
? Forms!myForm!tbxLName.Valu
Smith
? Forms!myForm!tbxLName.Text
Smitt
Hello Ray,
(re your comment in another thread - I would prefer fishing to doing this VBA stuff any day)
Thanks for pointing out the subtle difference we are dealing with here. I hope that by explaining what I understand we might be able to move on to my question or you can pick me up on why I am incorrect.
I have unbound text boxes. The textboxes need to be updated with each change made. For example imagine a form and at the top is a textbox labeled "Place of Holidays" at the bottom of the form is the text "We went on holidays to [space] and we went fishing"
Now what I am trying to do is that as the person types in the textbox "Place of Holidays" the below text is updated. So if in "Place of Holidays" the user types a "K" then the text below would now be "We went on holidays to K and we went fishing"
So back to the theory - I am using the onChange event for each textbox. When you check the .value and .text of this text box as you type, the .value does not change with each keystroke but the .text does. .Value will only change after the control is saved. Thus this means that to do what I want to do I have to use the .text property. However and annoyingly a control must have the focus to read the .text property, thus anywhere else in the code when I want to get all the contents of the textboxes I cannot use .text I have to use .Value.
As said before I have now just made two functions one with the text property and one with the value property, but I would like to know if it is still possible to combine these two functions into one by passing the property name to the function.
When the focus is on another control, you can momentarily set it back to txtPlaceOfHolidays, read the .text and return to the control that had the focus:
strCurrControl = Forms!frmName.ActiveContro
Forms!frmName.txtPlaceOfHo
strText = Forms!frmName.txtPlaceOfHo
Forms!frmName.Controls(str
That any help?
Thanks for the suggestion - yes you are right setting the focus on each box would work while going through them all, but not be so good when someone is actually typing in the box as focus would be taken away after each keystroke. ie each time the onChangeEvent happens.
You realise you are using an example by way of the controls which I would like to do with the properties. :-)
Forms!frmName.Controls(
I would love to be able to use this
Forms!frmName.txt_myte
Forms!frmName!txt_myTextBo
Here's what I've been able to come up with:
strMyProp = "Value"
myProp = "forms!frmName!!ttx_myText
? eval(myProp)
1671791 ' - stored value
' In here you need the code to make sure the textbox has the focus.
strMyProp = "Text"
? eval(myProp)
1671792 - edited value
My testing show that the first sentance above of GrayL is the answer to my specific question.
ie
"Forms!frmName!txt_myTextB
Thank you GrayL
Business Accounts
Answer for Membership
by: GRayLPosted on 2009-10-28 at 12:09:10ID: 25687009
This from VB Editor Window - Help
Text Property
See AlsoApplies ToExampleSpecificsYou can use the Text property to set or return the text contained in a text box or in the text box portion of a combo box. Read/write String.
expression.Text
expression Required. An expression that returns one of the objects in the Applies To list.
Remarks
You can set the Text property to the text you want to display in the control. You can also use the Text property to read the text currently in the control.
You can set or read this property only by using a macro or Visual Basic.
Note To set or return a control's Text property, the control must have the focus, or an error occurs. To move the focus to a control, you can use the SetFocus method or GoToControl action.
While the control has the focus, the Text property contains the text data currently in the control; the Value property contains the last saved data for the control. When you move the focus to another control, the control's data is updated, and the Value property is set to this new value. The Text property setting is then unavailable until the control gets the focus again. If you use the Save Record command on the Records menu to save the data in the control without moving the focus, the Text property and Value property settings will be the same.
Note that Value is not one of the enumerated Properties of any control. It is intrinsic to that control. The value 2455 is the Error Number of the error message, not a property value.