Full Version: Force Header To Add A Record Before Moving To Subform
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Louverril
I have a header form and a subform.

How can I force the user to add a record to the main from before moving to the subform?

The main form record just satays a a NEW record and therefore no events will fire to verify the data on the main form. So I can't use the before update event - it is just ignored as the main record is new. Even if I add a default value all the iser has to do if select Esc and the beofre update no longer fires beause the main record is set back to a new record.

Any ideas..

Access 2007

Thanks Lou
doctor9
Lou,

Assuming there's at least one control on the main form that needs to be filled in before you unlock the subform,here's some code you could use:

CODE
Private Sub Form_Current()
    LockUnlockSubform
End Sub

Private Sub strEmulDSROperator_AfterUpdate()
    LockUnlockSubform
End Sub

Private Sub dteEmulDSRTestDate_AfterUpdate()
    LockUnlockSubform
End Sub

Private Sub LockUnlockSubform()

    If Me.NewRecord = False Then

'       If both of the fields on the main form are filled in...
        If IsNull(Me.dteEmulDSRTestDate) = False And _
           IsNull(Me.strEmulDSROperator) = False Then

'           Unlock the form (but only if it's already locked)
            If Me.frmDSRTime.Enabled = False Then
                Me.frmDSRTime.Enabled = True
            End If
        Else
'           Lock the form (but only if it's already unlocked)
            If Me.frmDSRTime.Enabled = True Then
                Me.frmDSRTime.Enabled = False
            End If
        End If
    Else
'       Main form is on a new record - lock the subform
        Me.frmDSRTime.Enabled = False
    End If
    
End Sub


Hope this helps,

Dennis
Louverril
Thanks,

That worked well. And a good way of doing that for the future.

Thanks very much!!!

Lou.

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.