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!

placing cursor into a textbox if it's empty

Status
Not open for further replies.

markronz

IS-IT--Management
Mar 20, 2007
93
US
Hello everyone-
What I'm trying to do is basically make is so that when someone clicks the button to continue in my application, it checks to see if a certain text box on the excel page is blank. If it text box is blank, I just want it to place the cursor inside of the box. Here's a small section of my code:

Code:
If Len(Sheets("Type1").TextBox3.Value) > 0 Then
     Sheets("Type1").TextBox3.Select
End If

The code above doesn't work. It gives me this error:

"Run-time error '1004': Select method of OLEObject class failed"

So can anyone help me just place the cursor into the text box? Should be easy but I can't get it...

Thanks
-Mark
 
Also, just a note, I did mean to put = 0 above instead of > 0 for the length...
 



Hi,
Code:
If Len(Sheets("Type1").TextBox3.Value) > 0 Then
  With Sheets("Type1")
'activate the sheet
     .activate
     .TextBox3.Select
  End with
End If

Skip,

[glasses] [red][/red]
[tongue]
 
Hmmm, I still get the error when I do it that way too...
 
I found out that if I have my worksheet unlocked, and I try the above code, it does SELECT that textbox. But it doesn't place the cursor inside of it. So it appears that the .Select method isn't the correct one. Does anyone know what the correct one would be to place the cursor inside of it?

Thanks
 



That's the best that you can do on a SHEET. Can't PUT the cursor into the box like you can on a UserForm.

Skip,

[glasses] [red][/red]
[tongue]
 
Code:
If Len(Sheets("Type1").TextBox3.Value) > 0 Then
     Sheets("Type1").TextBox3.[COLOR=red]Activate[/color]
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top