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

How to reference text box values on different form

100+
P: 114
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
Share this Question
Share on Google+
7 Replies


ADezii
Expert 5K+
P: 8,597
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

100+
P: 114
'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

100+
P: 114
Anyone know how I can accomplish this.
Dec 29 '06 #4

P: 34
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

100+
P: 114
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

P: 34
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
Expert Mod 15k+
P: 31,186
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.