Save one form from another? (1 Viewer)

David R

I know a few things...
Local time
Today, 13:49
Joined
Oct 23, 2001
Messages
2,633
Setup:
One data entry form with subform (Contacts/subformContactDetails).
One search form for locating records in subformContactDetails(searchContactResolutions).

Situation:
If a user has the Contacts form open, and then goes to search for another Contact via the searchContactResolutions form, it will fail if subformContactDetails does not have all of its Required fields filled out. For that reason I was checking for the Dirty property, and banning it from moving records. However Access is overzealous in this, and if the user does not somehow remember to save the record before moving to the other window, it will still wonder if the record is incomplete (Dirty) and forbid it.
The current code looks like this (in searchContactResolutions):
Code:
    If (SysCmd(acSysCmdGetObjectState, acForm, "Contacts") > 0) Then
        If Forms!Contacts.subformContactDetails.Form.Dirty = True Then
            MsgBox "You must complete the current contact before opening another to be viewed.", vbCritical, "Record not completed"
            Exit Sub
        End If

Problem:
Rather than relying on the user's institutional knowledge that they have to save the record before they go search for a new one, I would like to force subformContactDetails to attempt to save itself before the move is executed.
The subformContactDetails_BeforeUpdate event checks for Required fields to be filled out, in order to guide the user to what they forgot. This is having a tendency to interfere with my attempts to automate the process.

In addition, it is not feasible to force the Contacts screen to save open losing focus, because people frequently have to visit other windows/forms in the process of filling out a contact.

Possibilities already tried:
If I use Forms!Contacts.FirstName.SetFocus to force the subform to save, then it fails miserably when the record cannot be saved. Because this is an event, not an error, I cannot (do not know how to) trap for it in the other form.

If I use DoCmd.RunCommand acCmdSaveRecord then it tells me I cannot save the record, because the searchContactResolutions form is non-updatable. This would be the preferrable option, except I have never seen a way to specify that *another* form attempt to save its record. DoCmd.RunCommand doesn't have that option.

Ideas?

Thanks in advance,
David R
 
Last edited:

Users who are viewing this thread

Top Bottom