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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative to Sendkeys "{tab}"

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
I have these codes that validate the data entry:

Private Sub txtModel_Change()
With txtModel
If Len(.Text) = .MaxLength Then
SendKeys "{tab}"
'txtOwning.setfocus
End If
End With

Private Sub txtModel_Validate(Cancel As Boolean)
With txtModel
If Not (.Text = "") Then
strCriteria = "select model from valmod where model = '" & .Text & "'"
boolEntry = valEntry(.Text, .TabIndex)
If boolEntry = True Then
.Text = UCase(.Text)
Cancel = False
'txtOwning.SetFocus
Else
MsgBox ("Invalid Model Number. Right-click mouse to view list."), vbExclamation, "Validation"
Cancel = True
End If
End If
If Cancel = True Then
.SelStart = 0
.SelLength = .MaxLength
End If
End With
End Sub


I believe that the sendkeys "{tab}" would trigger the validation, but after validating, the cursor doesnt't go to the next textbox(txtOwning) but to the one after. If I hard-code the next textbox to have the focus in txtModel_change, the validation doesn't get executed and when I hard-code it on txtModel_validate, the cursor still goes to the textbox after the txtowning.

Any help will be greatly appreciated.


 
I had a problem similar to this...It seams that the {tab} works in the order that the control was entered...for example, you may have entered the control you don't want it to goto before you entered the control that you do want it to go to...Try setting the tab index on each textbox in the order you want them to cycle...eg:

txtModel.tabIndex = 1
txtNext.tabIndex = 2
txtLast.tabIndex = 3

Hope this helps ;) Rob
"Programming is like art...It makes me feel like chopping my ear off."
 
thanks rjr999!

I have set the tabindex for each of my text boxes during design time, so the order of the tabindex is in the order that I wanted to.

As I was playing around with it, I came up with a messy and code-intensive solution to the problem. What I did is duplicate the code I have in the _validate routine into the _change routine. So far it worked on 3 textboxes and I still have 42 to go.

thanks again for you quick response.
 
42??? heh, good luck to ya ;) Rob
"Programming is like art...It makes me feel like chopping my ear off."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top