Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing textbox.text data in VBA (Access 2000)

Status
Not open for further replies.

wrbodine

Programmer
Aug 24, 2000
302
US
Hi,

I have a number of text boxes in an Access 2000 form that I want the user to enter data, and then will use as parameters for a stored procedure (in VBA, using a command object to call the stored procedure). The program is blowing up when I first try and access the .text property of the first text box (to build a parameter string). The error I get is:

Err.number = 2185
Err.description = You can't reference a property or method for a control unless the control has the focus.

I'm wondering if this could be in the way the command button was set up, but am not sure. Does anyone have any ideas?

Thanks,
Ray
 
Had a similar problem. Just precede the access to the textbox with a textbox.setfocus() method call. Then you can access the text box. Don't know why you have to do it. But it works.
 
Instead of setting focus, I just reference the default property. Which, in the case of a text box, happens to be the Text property.

I.E.

Me.Text1.text and me.text1 return the same value. With the exception being in the second case, you don't have to set focus first.

Remeber, this only works with the default property. In other words, me.text1 will not return the Width of the text box..... Tyrone Lumley
augerinn@gte.net
 
Thanks Tyrone, that's helpful. I was doing babymaker way but this will save a few lines of code....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top