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

Setting field focus

Status
Not open for further replies.

ncscott

MIS
Jan 10, 2003
36
US
I have a table-linked form I've created in VB 6. Here's what I'm trying to do. We have:
Field 1
Field 2
Field 3

Here is the desired behavior. Upon form activation, focus goes to field 2. A value is entered. If this value matches one of a list of values, that value is entered in field 1, and I need field 2 to be blanked out and focus to remain on field 2. If the value entered in field 2 is not in the list, the value should be entered in field 2 and focus should go to field 3.

Currently, if I enter a value which is in the list in field 2, it properly populates field 1 with that value, but the cursor then moves to field 3, following the default tab order. What I tried to do was to include "Field2.setfocus" in the Change procedure for field 1, so that when a value from the list was entered in field 2, it would be placed in field 1 and focus would return to field 2.
That didn't work. Neither did placing "Field2.setfocus" in the LostFocus procedure of Field 1, which didn't work either. In fact, the SetFocus command doesn't seem to be having any affect at all. What other options are there?
 
Try using the Validate event for Field2. If you want the focus to remain on field2 then set the text property to "" and then set the Cancel parameter to true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top