View Full Version : Text Property problem


harrymahal
10-28-2001, 04:32 AM
Hi...

I am using Access for the first time and am having trouble.

I have to set up a form containing a Text Box, A Label and a Button. I have to write a Caption on the Label asking the user to enter a name. Also I have to edit the Text Box's Text Property to leave it blank. I do not know how to do this.

The code attached to the button is:

Private Sub Command1_Click()
Label1.Caption = Text1.Text
End Sub

So when I clcik on the button, the Label should display the user's name.

But I keep getting an error:

Run-time error '2185':

You can't reference a proerty or method for a control unless the control has the focus.

I don't know what this error means....

Please help.....as I am just a beginner

Thankyou in advance

Harry

scottfarcus
10-28-2001, 06:09 AM
If you use refer to the Text property of the text box, it will have to have the focus to perform this function. The following would work...

Private Sub Command1_Click()
Text1.SetFocus
Label1.Caption = Text1.Text
End Sub

The Text property is the default property of a text box, so if you don't want to set the focus to the text box, use the following...

Private Sub Command1_Click()
Label1.Caption = Text1
End Sub

Good luck!



[This message has been edited by scottfarcus (edited 10-28-2001).]