Results 1 to 12 of 12
  1. #1
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94

    Button on form A to open form B with subform -- with subform AllowEdits = False

    Windows 7 Access 2016


    I am a newbie so excuse me if I use the wrong words.

    I have a button called "OpenRead" on my "frmStart" form. When it is click I want to open a different form "frmTab_AllBeneficiariesDetails" which has two tabs with subforms. On one of the tbs is the form called "Sub_frmTab_AllBeneficiaries2_Main"
    I want to make the subform call "Sub_frmTab_AllBeneficiaries2_Main" to not allow edits. The below code has an error in the third line. I am not calling out correctly the subform. ?????

    Code:
    Private Sub OpenRead_Click()
    DoCmd.OpenForm "frmTab_AllBeneficiariesDetails", acNormal
    Me!"Sub_frmTab_AllBeneficiaries2_Main" AllowEdits = False
    End Sub
    Last edited by TenOc; 03-14-2019 at 09:29 PM.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    use the FULL path to turn on/off properties if theres more than 1 form...


    DoCmd.OpenForm "frmTab_AllBeneficiariesDetails"

    forms!frmTab_AllBeneficiariesDetails!Sub_frmTab_AllBeneficiaries2_Main.enabled = false

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If the sub form "Sub_frmTab_AllBeneficiaries2_Main" is only used as a sub form in the form "frmTab_AllBeneficiariesDetails", the easiest thing to do is:
    1) open the sub form "Sub_frmTab_AllBeneficiaries2_Main" in design view.
    2) Open the form properties.
    3) Click on the DATA tab.
    4) Set the properties Allow Additions, Allow Deletions and Allow Edits to FALSE
    5) Close the form and save the changes.


    If the sub form "Sub_frmTab_AllBeneficiaries2_Main" is used to add/edit data in other forms or stand alone, then you will have to use code to make the form read only.
    1) first, make sure that the sub form control has a different name than the sub form itself. It just makes it easier to refer to the sub form control.
    (If you drag a sub form named "SFMySubForm", Access names the sub form control with the same name )

    Lets say
    The main form name is "frmTab_AllBeneficiariesDetails"
    The sub form name is "Sub_frmTab_AllBeneficiaries2_Main"
    And the sub form CONTROL is named "MySubFormControl"

    2) Try this code:
    Code:
    Private Sub OpenRead_Click()
        DoCmd.OpenForm "frmTab_AllBeneficiariesDetails"
    
        With Forms!frmTab_AllBeneficiariesDetails!MySubFormControl.Form
            .AllowAdditions = False
            .AllowDeletions = False
            .AllowEdits = False
        End With
    
    End Sub
    Last edited by ssanfu; 03-14-2019 at 06:07 PM. Reason: My bad - corrected sub name

  4. #4
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94
    If the sub form "Sub_frmTab_AllBeneficiaries2_Main" is used to add/edit data in other forms or stand alone, then you will have to use code to make the form read only.

    The subform is also use as full edit by different uses. Depending on which user is logged in the "edit" or "read only" button on From A is visible or hidden.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    OK, then try the code option as shown.

  6. #6
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94
    Still doing something wrong, I have worked an hour trying different syntex. Current code gets and "Object does not support this method" error.



    Private Sub OpenRead_Click()
    DoCmd.OpenForm "frmTab_AllBeneficiariesDetails", acNormal


    Forms!frmTab_AllBeneficiariesDetails!Sub_frmTab_Al lBeneficiaries2_Main.MySubForm.ControlForm AllowEdits = False




    'Me!Sub_frmTab_AllBeneficiaries2_Main.Form!AllowEd its = False


    'Me!Subform1.Form!ControlName.Enabled


    End Sub

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    OK...just to be sure:

    What is the main form name?
    What is the sub form name?
    On the main form, what is the SUB FORM CONTROL name?




    When posting code, please use the code tags (click the hash tag (#) in the menu)

  8. #8
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94
    Quote Originally Posted by ssanfu View Post
    OK...just to be sure:

    What is the main form name?
    What is the sub form name?
    On the main form, what is the SUB FORM CONTROL name?




    When posting code, please use the code tags (click the hash tag (#) in the menu)
    See the original post for names of the forms. I do not understand "On the main form, what is the SUB FORM CONTROL name?"

  9. #9
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94
    It looks like the below code works. Now I need to test it more.

    Code:
     
    Private Sub OpenRead_Click()
    DoCmd.OpenForm "frmTab_AllBeneficiariesDetails", acNormal
    
    Forms!frmTab_AllBeneficiariesDetails!Sub_frmTab_AllBeneficiaries2_Main.Enabled = True
    Forms!frmTab_AllBeneficiariesDetails!Sub_frmTab_AllBeneficiaries2_Main.Form.AllowEdits = False
    
    End Sub

  10. #10
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    To add a form inside another form, you must use a subform control. There are two methods.
    The simplest method is to just drag a form onto another form. The subform control is automatically created.

    The other method is to click on DESIGN in the menu, then click on the subform control icon.
    Click image for larger version. 

Name:	ribbon1.png 
Views:	10 
Size:	53.9 KB 
ID:	37842
    If you have Wizards enabled, it will walk you through how to add a form to the control.


    If you open the property sheet dialog box and select the SUB FORM CONTROL (see below), you can click on the DATA tab and see the form name of the form contained in the sub form control.
    Click image for larger version. 

Name:	Subformn1.png 
Views:	10 
Size:	196.3 KB 
ID:	37844

    So.... a Text Box control has a name, a Combo Box control has a name, a List Box control has a name and a Subform control has a name.



    You wouldn't answer, so the I'll answer (correctly I hope) the first 2:
    What is the main form name? "frmTab_AllBeneficiariesDetails"
    What is the sub form name? "Sub_frmTab_AllBeneficiaries2_Main"

    So, what is the SUB FORM CONTROL name on your form "frmTab_AllBeneficiariesDetails"?????


    Once you know the sub form control name, replace MySubFormControl with your sub form control name in the code below
    Code:
    Private Sub OpenRead_Click()
        DoCmd.OpenForm "frmTab_AllBeneficiariesDetails"
    
        With Forms!frmTab_AllBeneficiariesDetails!MySubFormControl.Form
            .AllowAdditions = False
            .AllowDeletions = False
            .AllowEdits = False
        End With
    
    End Sub



    If you still can't get the code to work, post your dB. (first do a "Compact and Repair", then zip (compress) it.
    Max Ziped size is 2 MB.

  11. #11
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Ack!!! you posted before I could get my post completed.


    Good luck with your project.

  12. #12
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94
    Thanks everyone !!!!

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

Similar Threads

  1. Replies: 4
    Last Post: 08-10-2018, 12:00 AM
  2. Query button on form to open results on subform
    By SierraJuliet in forum Queries
    Replies: 2
    Last Post: 01-15-2018, 10:04 PM
  3. Replies: 2
    Last Post: 11-27-2011, 07:08 PM
  4. Form combo box not working with AllowEdits = False
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 02-04-2011, 05:08 PM

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