473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Simple (I think) scope question

Hi, I have just started trying to use Access to add some functionality to a form I was given. I have no experience with this language and am having some difficulty accessing text from another textbox.

As an example, I tried making a simple form that combines two strings from different text boxes and put it into a third with a button click, but I get an error, specifically "Run-time error '2185': You can't reference a property or method for a control unless the control has the focus."

Here's the code I wrote to control the three text boxes(txtFirstName, txtLastName and txtFullName) and the button(stringButton):
Option Compare Database

Public Sub stringButton_Click()

txtFullName.Text = txtFirstName.Text & " " & txtLastName.Text

End Sub
I don't know how to make these objects visible outside their own subroutines since I don't have a say as to where they're created. My only language experience is JAVA so I'm at a loss here. Any help would be greatly appreciated.

Thanks,
Tim
May 22 '07 #1
6 1459
ChaseCox
294 100+
Ok. I think this will do what you want. I can explain anything if you want me to. You can use the SetFocus command to get the job done.

Expand|Select|Wrap|Line Numbers
  1. Public Sub Helping_Click()
  2.  
  3. Dim var1, var2  As String
  4.      txtFirstName.SetFocus
  5.          var1 = txtFirstName.Text
  6.      txtLastName.SetFocus
  7.          var2 = txtLastName.Text
  8.      txtFullName.SetFocus
  9.          txtFullName.Text = var1 & " " & var2
  10.  
  11. End Sub
  12.  
Hope This Helps!
Regards
C. Cox
May 22 '07 #2
It does indeed, Thank you very much
May 22 '07 #3
ChaseCox
294 100+
It does indeed, Thank you very much
You are welcome. There may be a simpler way, but that is what I thought of right away.
May 22 '07 #4
missinglinq
3,532 Expert 2GB
There is indeed a much simpler way! You simply change the Text property to the Value property.

txtFullName.Value = txtFirstName.Value & " " & txtLastName.Value

As you found out, for the Text property to work the control has to have focus. The Value property doesn't require this! And actually, because Value is the default property for textboxes, you can make it even simpler:

txtFullName = txtFirstName & " " & txtLastName

To be honest, I think the only reason the Text property is still around is to make Access backward compatible. Value is obviously much more flexible!
May 22 '07 #5
ChaseCox
294 100+
Thats what I was wondering. I had never used the .text property until I saw this post. And I could not remember how I managed to set text box values in the past. That is what I did, thanks for the tag-team. :-)
May 22 '07 #6
OldBirdman
675 512MB
The text property has uses beyond backward compatability. It allows the program to monitor the entry of text data while the entry is in progress.

You might code as below and eliminate the stringButton altogether.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtFirstName_Change()
  2.     txtFullName = txtFirstName.Text & " " & txtLastName
  3. End Sub
  4.  
  5. Private Sub txtLastName_Change()
  6.     txtFullName = txtFirstName & " " & txtLastName.Text
  7. End Sub
  8.  
May 25 '07 #7

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

Similar topics

2
by: nos | last post by:
I have two files in the same directory which is '.' I have a method in file1 that I invoke from a method in file2. Why do I have to use class1.method1() instead of just method1(). The...
6
by: Arthur J. O'Dwyer | last post by:
I was paging through Coplien's book "Advanced C++ Programming Styles and Idioms" this afternoon and found some code that looked something like void sort(vector<foo> a) { int flip; do { for...
23
by: NotYetaNurd | last post by:
for(int i=0;i<6;i++) { // } wont i go out of scope after the for loop ...?
9
by: arnuld | last post by:
hello folks, i have a simple one line question. i am planniing to 1st learn Assembly & then C++: are there any jobs that i can get by learning C++? -- if yes, what type of jobs are...
2
by: mattdaddym | last post by:
Hi, I have a variable question in regards to my asp .net page. I need to declare a variable whose value is readable/writable to all of the subroutines of a specific page. So far I have one of two...
20
by: David | last post by:
I feel like an idiot asking this but here goes: I understand the 'concept' of scope and passing data by value and/or by reference but I am confused on some specifics. class example{ int i; //my...
2
by: Gabe Moothart | last post by:
Hello, In one of my asp.net applications, I create a series of checkboxes, set their properties, and give them an "onChecked" event handler on the fly using an anonymous method. The code looks...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
3
by: civettina | last post by:
Hi, I'm trying to send an email to' sample@sample.com' when a new row on my table contactform_con is inserted. Basically, when a person fills out the contact form (contactform_con) I want one...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.