Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default TextBox.SetFocus

I have a form in my VBA (Excel 97 SR2, Win2000) and am using the below code
to format the data entry after update. Also to reselect the Textbox if the
entry is incorrect (I will check later to determine if it is a numeric
entry).

My question: I am using SendKeys to re-activate the TextBox, but have heard
that SendKeys is not reliable. Have tried
QForm.TextBox55.SetFocus
to no avail. (Searched Google and got the SendKeys solution)

Can anyone help make this work?

Thanks in advance!!!

steve
====================================
Private Sub TextBox55_AfterUpdate()
Dim phn ' note not defined so that it shows as number on sheet
phn = QForm.TextBox55
If Len(phn) < 7 Or Len(phn) < 10 Then
phn = MsgBox("Phone number incorrect." _
& Chr(10) & "ReEnter number.", vbOKOnly)
Application.SendKeys ("+{tab}")
Exit Sub
ElseIf Len(phn) = 7 Then
phn = Format(TextBox55, "000-0000")
ElseIf Len(phn) = 10 Then
phn = Format(TextBox55, "(000) 000-0000")
End If
QForm.TextBox55 = phn
End Sub
===================================


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default TextBox.SetFocus

If you use beforeupdate to do the validation, all you have to do is set
Cancel = true to stay in the box

Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
if "not validated" then _
Cancel = True

End Sub

Regards,
Tom Ogilvy


"steve" wrote in message
...
I have a form in my VBA (Excel 97 SR2, Win2000) and am using the below

code
to format the data entry after update. Also to reselect the Textbox if

the
entry is incorrect (I will check later to determine if it is a numeric
entry).

My question: I am using SendKeys to re-activate the TextBox, but have

heard
that SendKeys is not reliable. Have tried
QForm.TextBox55.SetFocus
to no avail. (Searched Google and got the SendKeys solution)

Can anyone help make this work?

Thanks in advance!!!

steve
====================================
Private Sub TextBox55_AfterUpdate()
Dim phn ' note not defined so that it shows as number on sheet
phn = QForm.TextBox55
If Len(phn) < 7 Or Len(phn) < 10 Then
phn = MsgBox("Phone number incorrect." _
& Chr(10) & "ReEnter number.", vbOKOnly)
Application.SendKeys ("+{tab}")
Exit Sub
ElseIf Len(phn) = 7 Then
phn = Format(TextBox55, "000-0000")
ElseIf Len(phn) = 10 Then
phn = Format(TextBox55, "(000) 000-0000")
End If
QForm.TextBox55 = phn
End Sub
===================================




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default TextBox.SetFocus

Tom,

As always - you came through AND so quickly!
Thank you!

My ignorance is showing as I used the following:

Private Sub TextBox54_BeforeUpdate(ByVal Cancel As
MSForms.ReturnBoolean)
Dim phn
phn = TextBox55
If Len(phn) < 7 Or Len(phn) < 10 Then _
Cancel = True

End Sub

wasn't sure how to use:
if "not validated" then _
Cancel = True

steve

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default TextBox.SetFocus

What you did is what you meant - I was just representing if the criteria was
not passed, then set cancel = true - which is the way you wrote your code.

Regards,
Tom Ogilvy

"steve bell" wrote in message
...
Tom,

As always - you came through AND so quickly!
Thank you!

My ignorance is showing as I used the following:

Private Sub TextBox54_BeforeUpdate(ByVal Cancel As
MSForms.ReturnBoolean)
Dim phn
phn = TextBox55
If Len(phn) < 7 Or Len(phn) < 10 Then _
Cancel = True

End Sub

wasn't sure how to use:
if "not validated" then _
Cancel = True

steve

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default TextBox.SetFocus

Tom,

Thanks! Again!

Understanding is slowly coming... Have been working with it and am
getting the desired results.

as always...

steve

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate Textbox value based on another textbox value.doc Tdungate Excel Discussion (Misc queries) 1 February 12th 09 07:11 PM
Calculate Textbox value based on another textbox value Tdungate Excel Discussion (Misc queries) 0 February 12th 09 07:03 PM
TextBox Jimbo1 Excel Discussion (Misc queries) 2 April 20th 06 02:47 PM
SetFocus on a different sheet in VBA AaronC Excel Discussion (Misc queries) 1 June 9th 05 11:18 PM
Textbox Greg Excel Discussion (Misc queries) 3 April 3rd 05 09:38 AM


All times are GMT +1. The time now is 12:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"