Add a new record to a subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Owino
    New Member
    • Dec 2009
    • 4

    Add a new record to a subform

    Hi

    I'm trying to add a new record to a subform called itemsreceived_s ubform, using a command button. I can't get the clear difference between the subform control, and the subform itself. My code is as follows:

    Private Sub cmdadd_Click()
    If Me!Itemsreceive d_subform.Form. Dirty Then
    Me!Itemsreceive d_subform.Form. Dirty = False
    End If

    Me![Itemsreceived subform].SetFocus ' This is the name of the subform

    DoCmd.GoToRecor d , , acNewRec

    End Sub
    ----------------------------------------------------

    Any ideas? Thank you.
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    You have not given any indication of the difficulty you are having, but you could try this (your code was adding a new record to the main form)
    Code:
    Private Sub cmdadd_Click()
        If Me!Itemsreceived_subform.Form.Dirty Then
            Me!Itemsreceived_subform.Form.Dirty = False
        End If
    
        Me.Itemsreceived_subform.AllowAdditions = True 'THIS IS REQUIRED IF SET TO FALSE IN DESIGN VEW!!
        Me.Itemsreceived_subform.DataEntry = True
    End Sub
    Just a thought.


    MTB

    Comment

    • Daniel Owino
      New Member
      • Dec 2009
      • 4

      #3
      Thanks

      Thanks for your help, it worked out fine.

      Comment

      Working...