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

"Auto-tab" when criteria is fulfilled 1

Status
Not open for further replies.

Mollethewizard

IS-IT--Management
Nov 18, 2002
93
SE
Got a user form with textboxes for name, address, zip code, city and an OK-button. Code written for the txtZipcode exit event that calls a subroutine with a number of cases. The idea is that if the zipcode corresponds with a case then txtCity = the case.

Hope that you follow this far.

What I would like is that when the above criteria are fulfilled (the txtCity textbox is “entered”) the user doesn’t have to tab to the next control – in this case the OK-button.

Any suggestions for code – and in that case where should it be inserted? In the change, enter, or exit-event for txtCity or somewhere else?

Christer
 
Hi Christer,

The Exit Event is good enough, or you could use the AfterUpdate; it depends a bit on what else you want to do.

Code is something like ..

Code:
[blue]Select Case txtZipcode
    Case "12345"
        txtCity = "AA"
        btnOK.SetFocus
    Case 13579
    :
    :
    Case Else
        txtCity.SetFocus
End Select[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Thanks for your reply Tony!

I forgot to tell you all that the ”cases” is in a sub that are called for from the zip code-exit event. And I’ve got more user forms that have other controls following the txtCity textbox.

Is it possible to write the “tab-code” in some way in the txtCity box?

Christer
 
Hi Christer,

It is possible to put it in the Enter Event of txtCity. The tricky bit may be finding a suitable condition to test; again it depends! It may be as simple as ..

If txtCity <> "" then Me.btnOK.Setfocus

Or, you may need to have a flag in (in the general declarations section at the top of) your Form which you pass to the subroutine so that it can set it for you to test later.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Tony – has anyone told you that you are among the geniuses – at least in the field of VBA.

The code works perfectly for my needs and once again I sit amazed how simple it looks when you have the answer.

Thanks a million times.

Christer
 
Thanks, Christer,

My pleasure!

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top