Results 1 to 6 of 6
  1. #1
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52

    Just Looking for Clarification...

    I have a form "frmRecipes" that contains subform "frmIngredients". Both are set so as to not allow any additions or edits.

    I am creating a button called "Add" on frmRecipes which will need to add records to the tables associated with both forms.



    I understand that the following code will allow me to add a new record on the main form:
    Code:
    Private Sub btnAdd_Click()
        Me.AllowAdditions = True
        DoCmd.GoToRecord , , acNewRec
        Me.txtRecipeName = " "
        Me.AllowAdditions = false
    End Sub
    If I were to modify the code so as to do this, would that Me.AllowAdditions refer to frmRecipes or my frmIngredients?
    Code:
    Private Sub btnAdd_Click()
        Me.AllowAdditions = True
        DoCmd.GoToRecord , , acNewRec
        Me.txtRecipeName = " "
        Me.AllowAdditions = False
      
        DoCmd.OpenForm "frmIngrendients"
        Me.AllowAdditions = True                  '  <------- THIS ONE <-----------
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The button is on the main form? The Me. reference is for the main form. The Me alias always refers to the form or report the code is behind regardless of where focus is.

    Since frmIngredients is a subform on frmRecipes, why do you want to open another instance of the form?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52
    I only set to open it because I thought changing the focus might allow me to change the "Me." reference.

    Is there a way to add a record for my subform from my main form?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Options:

    1. change form properties as you are currently trying - addressing a subform to do this is tricky

    2. maybe opening the second instance of subform will allow directly referencing the form - I've never tried multiple instances of a form
    Forms!frmIngredients.AllowAdditions = True

    3. programmatically add records to the underlying tables and then requery the form/subform
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2014
    Posts
    52
    Hmm... all right, I'll mull this over a bit.

    Thanks for the help!

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by faythe1215 View Post
    I have a form "frmRecipes" that contains subform "frmIngredients". Both are set so as to not allow any additions or edits...


    You need to understand that the Subform is actually a Subform Control, and as such, regardless of how AllowAdditions is set for the Form the Subform is based on, you will not be able to add Records as long as the Main Form is not editable! The Access Gnomes consider anything you try to do to the Subform as 'editing' it.

    Linq ;0)>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. One simple request - Clarification
    By shani20 in forum Access
    Replies: 2
    Last Post: 01-26-2015, 08:35 AM
  2. record-level locking clarification
    By vientito in forum Access
    Replies: 3
    Last Post: 11-12-2014, 09:39 AM
  3. Replies: 9
    Last Post: 11-27-2013, 11:08 AM
  4. Query Performance Clarification
    By shabar in forum Queries
    Replies: 3
    Last Post: 01-29-2013, 03:38 AM
  5. clarification with transfer commands
    By mike02 in forum Access
    Replies: 7
    Last Post: 08-08-2012, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums