469,333 Members | 4,367 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,333 developers. It's quick & easy.

How to reference text box values on different form

114 100+
Have a need to reference a value in 1 or 2 text box(s) on a prior form. Based on the value(s) entered, I may need to clear out 1 or 2 value(s) that where entered but not required in a couple of text boxes on the prior form.

Not sure how to reference those text boxes in the dot notation used in VBA. I tried to use the Me.Refresh but that is not working. Is the Me. used to indicate the current working form?
Dec 28 '06 #1
7 76004
ADezii
8,800 Expert 8TB
Have a need to reference a value in 1 or 2 text box(s) on a prior form. Based on the value(s) entered, I may need to clear out 1 or 2 value(s) that where entered but not required in a couple of text boxes on the prior form.

Not sure how to reference those text boxes in the dot notation used in VBA. I tried to use the Me.Refresh but that is not working. Is the Me. used to indicate the current working form?
'To refer to a value in a Text Box named txtTest on frmTest from another Form,
'you can use this syntax:

Expand|Select|Wrap|Line Numbers
  1. Forms![frmTest]![txtTest].Text
Dec 28 '06 #2
ljungers
114 100+
'To refer to a value in a Text Box named txtTest on frmTest from another Form,
'you can use this syntax:

Expand|Select|Wrap|Line Numbers
  1. Forms![frmTest]![txtTest].Text
I tried this in my VBA script just before I perform a DoCmd.OpenForm stDocName, , , stLinkCriteria

have loaded the form name in stDocName after testing a couple of variables and based on that test I need to clear the values before that form is used again. Here is what I did but I'm getting the following error when I run it.

"You can't reference a property or method for a control unless the control has focus"

Forms![MemoLukupForm]![WhatLastName].Text = ""
Forms![MemoLukupForm]![WhatFirstName].Text = ""
Forms![MemoLukupForm]![WhatRecNo].Text = ""
Dec 28 '06 #3
ljungers
114 100+
Anyone know how I can accomplish this.
Dec 29 '06 #4
I came across this today for a similar problem

it's for the Value Property

The Text property returns the formatted string. The Text property may be different than the Value property for a text box control. The Text property is the current contents of the control. The Value property is the saved value of the text box control. The Text property is always current while the control has the focus.
try the .value instead of the .text see if that works

I was getting data though, not changing it
Dec 29 '06 #5
ljungers
114 100+
The .Value instead of .Text works, and the text boxes are clearned prior to returning to the 1st form.

Now the problem I'm having is after keying in new data in these cleared text boxes and clicking the button labeled "Search" that uses OnClick "LukupQuery".

The query seems to return nothing because a list box that uses that query results RowSourceType = table/query and RowSource = LukupQuery is now empty.

I have also noticed that my Query SQL window and the 2nd form window with the list box remain open.

Looks like something is not being done. Can some one tell me when, where and how a Refresh, Requery should be done? Should I be closing the 2 windows (query sql, 2nd form) if so, what is the VBA code to do just that.

Thanks
Dec 29 '06 #6
The .Value instead of .Text works, and the text boxes are clearned prior to returning to the 1st form.

As I am in no way an expert, could a expert confirm that the .Value is a good way to get past the "can't reference a control error?"
Dec 29 '06 #7
NeoPa
32,182 Expert Mod 16PB
It is, but a better way is simply to reference the control (.Value is the default property).
The OP doesn't specify what he means by the 'prior form', so we can only assume that it is a currently open form but not directly related to the current form (Me). In that case Forms!FormName.ControlName is a perfectly usable way to access the control.
Forms is another way of saying CurrentDB.Forms and Forms!FormName is another way of saying Forms.("FormName").
Dec 30 '06 #8

Post your reply

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

Similar topics

14 posts views Thread by rgreen3 | last post: by
11 posts views Thread by joey.powell | last post: by
2 posts views Thread by Fred | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.