Two (sub)forms accessing the same table - save before changing focus?

V

Vincent Verheul

Hi,

I have a main form that is unbound and has several subforms. I change the
SourceObject of the subform depending on the user's choice. This may result
in a situation where two subforms access the same table: using filters, the
same record may appear in both forms, but different fields are displayed on
each form.

The user can leave one form with the record in a 'Dirty' state an move focus
to the other form (same record), also attempting to make a change. Now of
course I get locking problems or the error "The data has been changed".

I have been looking for an event like Form_LostFocus, but is does not seem
to be triggered when I go from Form1 to a button on Form2. If I have that
event, I can check the 'Dirty' state and save the record before leaving the
form.

How can I detect that the user leaves (sub)Form1?

(Using XP and Access 2002).

Thanks!
Vincent
 
G

Guest

I didn't test because I could not duplicate it in here.

Use the event OnExit of the Subform object:

Private Sub Subform1_Exit(Cancel As Integer)
If Subform1.Form.Dirty Then
MsgBox "Please, apply changes before leave !", vbOKOnly +
vbExclamation
Cancel = True
End If
End Sub

Mauricio Silva
 
V

Vincent Verheul

Got it already : the OnExit event of the control on the main form that holds
my subForm1 is triggered when focus moves away.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top