Prevent data entry in subform if no records in parent form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry Maiapu
    Contributor
    • Feb 2010
    • 259

    Prevent data entry in subform if no records in parent form

    Can please someone help me out. I am a beginner (of VB)
    I have a main form with a sub form created based on two tables having one to many relationships.
    i want to prompt the users a message preventing them from entering records in the sub form if the parent form has no records at all. How can i do that
    Thanks alot

    Jerry Maiapu
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    When you accept the proposed linkage field when placing a subform with the wizard, then there will be no problem with adding "child records" under a "Master" record, as Access will prevent this automatically.

    Nic;o)

    Comment

    • Jerry Maiapu
      Contributor
      • Feb 2010
      • 259

      #3
      Thanks. I got help from office online as well

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Hi Nico
        To make it work like that you would need to set the Foreign Key field to be a required field (Which is a good idea anywho). Atleast this goes in Access 2003. Without the required field i get no error message when adding something to a subform, without adding something to main form first.

        There may be a more elegant solution but what I can think of right now is simply to add to the form_Current event:
        Code:
        Me.frm_Sub.Enabled = Not Me.NewRecord
        And then probably add the same code to Forms AfterUpdate

        Comment

        Working...