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!

LostFocus event....

Status
Not open for further replies.

ItIsHardToProgram

Technical User
Mar 28, 2006
946
CA
I have a function that checks for a boolean variable and if that variable is set to false, it needs to cancel the losing focus event, and reset focus. so what I did is a simple if, with a msgbox and if it is false then
Forms![Feuille_Temps_F1]![SelSem].SetFocus

Unfortunatly that does not stop the user from losing focus, why??? (it does not setfocus back on the combo box.)

I tried a cancelevent also, still no effect....
 
Use the Exit event instead, then you can use the Cancel argument (Exit event has Cancel, LostFocus does not).

HTH,

Ken S.
 
Thanks, your right, I dint notice the Exit event, another question regarding a related issue, is there a way of preventing the record from being written down (bound txtboxes) if some of the fields were not filled? (prevent errors in database.)

I would like to evade the recordset :/
 
Probably the simplest way is to edit the table in design view and set the "required" property on the fields in question to "yes."

Otherwise you could use the form's BeforeUpdate event to validate your data and use either Cancel or Undo to prevent bad or null data being written.

Ken S.
 
ItIsHardToProgram said:
[blue] . . . is there a way of preventing the record from being written down (bound txtboxes) if some of the fields were not filled?[/blue]
You'll have to use your own [blue]Validation Scheme[/blue] in the [blue]BeforeUpdate[/blue] event of the form . . .

Calvin.gif
See Ya! . . . . . .
 
Just one last question, doesnt every field write down seperatly in the table, and so I would have to put a validation scheme in every single beforeupdate of my form, or would passing through a delete request on the close event of the form be a good work around.

 
ItIsHardToProgram said:
[blue] . . . doesnt every field write down seperatly in the table, and so I would have to put a validation scheme in every single beforeupdate of my form[/blue]
Wrong Idea! . . .
1st . . . a record isn't saved until you:
[ol][li]Move to a different record.[/li]
[li]Save a record thru VBA.[/li]
[li]Close the form.[/li][/ol]
For a record to be saved it has to be in edit mode (depicted by the pencil icon in the record selector). Edit mode is triggered when you start editing a record.

With the above in mind,the [blue]Before/AfterUpDate[/blue] events of a field occur [purple]in relation to updating the field[/purple] (not saving). The [blue]Before/AfterUpDate[/blue] events of the form [purple]occur in relation to saving the record[/purple].

So you can check all fields in the forms BeforeUpdate event! . . . If a field doesn't pass validation you can use the [blue]Cancel[/blue] arguement to roll back saving.

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top