TextBox1.SetFocus doesn't work (word2003)
hi there,
I made a very simple vba program using word2003 with 3 texboxen for input, and some labels for calculated output ( simlpe tax caculation with variable tax % ), 1 commandbutton to start calculating, and 1 commanbutton to " reset" the whole thing( clears the 2 input textboxen, and keeps the tax % texbox).
all works well, but when i push the Reset button, all gets erased, but the setfocus won't work.
code ( when reset button is pushed) is something like:
textbox1.text = clear
...
texbox1.setfocus
end
i would also like to use the tab key to go from inputbox to inputbox, how do i achieve that ?
greets and thanks in advance
sven
Re: TextBox1.SetFocus doesn't work (word2003)
hi,
to get focus to the text box you want, try setting focus to another object on screen first, before going back to the one you want.
e.g.:
VB Code:
'you want focus to go to text1
text2.SetFocus
text1.SetFocus
to go from one input box to another, you need to look at the 'Tab Order' of the text boxes, and put them into the sequence that you want.
HTH
Re: TextBox1.SetFocus doesn't work (word2003)
hey,
Textbox1.SetFocus didn't work in any way..
TextBox1.Select does :-)
thanks for helping me anyway, still working on that tab, but right now i'm at school and supposed to do other things
thanks, and have a nice weekend
sven
Re: TextBox1.SetFocus doesn't work (word2003)
There is no TextBox1.SetFocus in Word :( Theequilivalent is like posted, TextBox1.Select :)
Re: TextBox1.SetFocus doesn't work (word2003)
ah, i see.
if you have objects directly on the word document you cannot set focus which makes sense i suppose.
but if you create a custom form, then you can use SetFocus within the forms code module.
Re: TextBox1.SetFocus doesn't work (word2003)
Yes, thats correct. Glad you made that point. I shouldnt have assumed that since the thread starter didnt
mention a userform, it wasnt being used.
:thumb:
Re: TextBox1.SetFocus doesn't work (word2003)
indeed, there is no user form involved, is that why i can't seem to get the tab key working ? I remember in VB 6.0 ( not vba ) that there was a "tab priority" to adjust, but i don't find anything like that in my Word VBA textbox properties ?
greets
sven
Re: TextBox1.SetFocus doesn't work (word2003)
try something like:
VB Code:
Private Sub TextBox1_Change()
If TextBox2 = validinput Then
TextBox2.Select
Else
MsgBox "Enter valid input", vbOKOnly + vbCritical, "Input Error"
End If
End Sub
you can remove the validation part of the above.
[EDIT]
the above doesnt work as it works after each character input so try the below:
VB Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
'sets focus to next text object when ENTER is pressed
'KeyCode = 9 can be used for TAB key
If KeyCode = 13 Then
TextBox2.Select
End If
End Sub
also, the things you are looking to do will work on a UserForm, as tab order and SetFocus can both be utilised.
is a User form an option for you?
Re: TextBox1.SetFocus doesn't work (word2003)
hi,
let me give you the full story so you can see what i'm trying todo.
i'm trying to convert a word file wich acts as an invoice ( for training only ) from a word file with tables, to a word file where you can input a product id number, and a number to indicate howmuch of product X the client wants, taxes and total price and productdetail will be inserted in labels when product id number and number of pieces are known.
so i started with my 2 textboxen and some cmdbuttons to do some very basic calculation just to see if it would work, and i got the impression that it would work, after i input al needed data ( some 100 products with id number and price and taxrate ( can be 6% 12% or 21% depending on the product )
my goal is to stay with the original word file, because, if i used a userform, i might as well start from scratch in vb6.
so, within my word file, everyting must work as desired ;-) incuding the "tab" function.
this is a freetime project for school.
saturdaynight 21:47, what am i doing here ? ;-)
thanks for helping me out
sven
Re: TextBox1.SetFocus doesn't work (word2003)
perhaps if you attach the word doc as it is just now, we can make some suggestions.
Re: TextBox1.SetFocus doesn't work (word2003)
In Word you can have up to 3 different types of TextBoxes. All of which are different in the way to handle the tabbing order.
You can have ActiveX TextBox, Word Form Field TextBox, and UserForm TextBox controls.
So if you could attach the document or provide a small screenshot of the textboxes, its really hard to solve.
1 Attachment(s)
Re: TextBox1.SetFocus doesn't work (word2003)
hi there,
sorry for my late reply, but i hope you can find my attached wordfile with the very basic calculation.
many thanks in advance for looking at it.
greets
sven
1 Attachment(s)
Re: TextBox1.SetFocus doesn't work (word2003)
You had the reset button set to take focus upon click. The setting was in the properties window for the reset button.
I also took out the Clear functions and replaced them with vbNullString.
Works fine now.
Re: TextBox1.SetFocus doesn't work (word2003)
thanks a lot for the effort ;-)
greets
sven