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

Setting the focus within a datasheet

Status
Not open for further replies.

aBill

MIS
Sep 24, 2002
26
US
I am having a strange bug.

I have a form that shows in datasheet view. When a certain field/control (ctl1) looses focus a modle is run to validate the field contents. If the contents are invalid, i want the control (ctl1) to give have the focus again.

I am attempting this using the simple setfocus method. This however is not working. Is there a restriction on using this when the form is displayed in a datasheet?

is there another solution?

simple i know, but annoying.

thanks in advance.
 
Not sure if this will help but it may be worth trying if the datasheet is a sub of the form...

You have two main objects that I named as follows for example purposes:

frmForm
dataSheet

Did you try

Forms!frmForm!dataSheet.SetFocus

MrMajik


Everything should be made as simple as possible, but not simpler
--Albert Einstein


 
Hi aBill,

I don't think it's anything to do with the view (form or datasheet) - it's just that you're in the wrong event. LostFocus occurs after the field has been updated and if you are validating I doubt if that's what you want. Put your validation in the BeforeUpdate event and set Cancel = True if it fails - that way the focus should remain on the control for user correction.

Enjoy,
Tony
 
Would you want something like a required field?

I have code for that for a subform within a mainform that I am using. This is related to a command button, which is really a close button. It checks all of my required fields including subform required fields and if the field is not populated it will not let them leave the form.

Would you want something like that?

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top