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

How to keep focus on a field in error on continuous form?

Status
Not open for further replies.

NCYankee1

Programmer
Mar 27, 2001
66
US
Hi

I have an Access XP subform on a form. The subform has 8 textboxes across, Monday-Sunday and 1 textbox for a code. The subform is set up as continuous forms so the user can just continue to type in data and have new rows appear for them as they go. My question is this: If they type something in error I can catch that error, but I can't keep the focus on the textbox with the error. If they click into a different row I then highlight the wrong textbox. Like if they made an error on the row 3 Tuesday box, it alerts them. But if they click into row 2 then the row 2 Tuesday box gets highlighted. How do I keep them on the row with the error?

Also, if they make an error in the 8th column and tab out, I know there is an error, but they are already on the next row. How can I keep the focus on the textboxes in error.

Thanks!
 
I haven't used continuous forms, so this idea might be out in left field. Still, it's worth a try. Have you tried setting the focus to Screen.PreviousControl in the error routine? What you really need to do is refer back to the record that was being entered when the error ocurred. If setting the focus to PreviousControl doesn't work, you might play around with saving a pointer to the record that the user is working on and returning to that record if there's an error, and setting the focus to the textbox in question. This is an interesting problem, and in the interest of expanding my own knowledge of Access, I'd be interested in how you get this to work if you have a chance to come back.

Thanks, and good luck!

dz
 
Use the BeforeUpdate event.
This is called before the record is saved. Put the code to check the textboxes in here, then if an error is found, set cancel=true and set the focus to the relevant textbox.
That way the record cannot be left until the user corrects the mistake, or cancels the edit.

Ben
 
The cancel=true is used for command buttons, right? There are no command buttons controlling things on this form. It is set up for the user to type,tab,type,tab,type,tab etc. When the tab out of the last box in the row it adds a new row for them to keep typing if needed. The edit check problem I am having is when they type something invalid, I pop them back to that field with SetFocus and tell them it is in error. But if they click on a different row it accepts the bad data and column that I had the SetFocus pointing to is highlighted. But on the wrong line. I need to try to contain them in the row with bad data. And that's where I am brain-cramping.
 
Cancel=True is used all over. Put code similar to this behind the BeforeUpdate event of your form. It checks each box, one at a time and as soon as it finds a box that doesn't meet it's criteria, it cancels the update, sets the focus to the bad text box and tells the user there is a problem.
If no errors are found it just carries on and saves the record.

Private Sub Form_BeforeUpdate(Cancel As Integer)
if me.txt1>100 then
cancel=true
me.txt1.setfocus
msgbox "Text Box 1 is duff!"
exit sub
end if

if me.txt2<>&quot;Orange&quot; then
cancel=true
me.txt2.setfocus
msgbox &quot;Text Box 2 is duff!&quot;
exit sub
end if
.
.
.
if me.txt99<=0 then
cancel=true
me.txt99.setfocus
msgbox &quot;Text Box 99 is duff!&quot;
exit sub
end if

End Sub

HTH

Ben ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top