Results 1 to 12 of 12
  1. #1
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328

    Refer to subform name in a module

    I am using A2007 and A2003. I am confused on basics of how to write a module in which I would conditionally change a sub form property to Allow or Not Allow edits

    On main form I have
    Call LockScreenM(F_FormName) I have tried putting form name in quotes and no quotes, doesn't matter

    In the module (stripped of all other non related lines)

    Public Sub LockScreenM(FN)



    With Screen.activeform
    .FN.Form.AllowEdits = True I get an error no 2465

    If I put the full name in like below, it works, but I need to be able to send several sub form names to the module depending on which main form form I am using.

    .F_FormName.Form.AllowEdits = True

    I tried googling, but couldn't find help, or just couldn't find right site. Any help much appreciated.

  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,625
    Try simply:

    Forms(FN).AllowEdits = True

    Works for me.

    Wait, you want to pass subform name? That I don't do. That does complicate.

    What are name of main form and name of subform and name of subform container control? There is only one subform on the main form?

    I just did a test of function:

    Function Test(MainForm)
    Test = Forms(MainForm).Form.AllowAdditions
    End Function

    Called the function in immediate window:
    ?Test("AirportData")

    Doesn't error but does not return AllowAdditions state of the subform.

    This does return AllowAdditions state of the subform:

    Function Test(MainForm, SubformContainer)
    Test = Forms(MainForm).Controls(SubformContainer).Form.Al lowAdditions
    End Function

    ?Test("AirportData", "ctrSections")
    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
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I am not sure what SubformContainer means. I assume that it is the name I enclose in parenthesis for calling the subform. I tried what I understood you recommended:
    Forms(Screen.ActiveForm.Name).Controls(FN).Form.Al lowEdits =false

    where FN is the "container name" for the subform. It gave me an error message about mismatch. .

    You knowledge exceeds mine by a lot, so even though you explain it, I might not understand. Could you just give me a simple example with say a Subform with name is "SubFrm1". (The name is different for various main forms that are in the system and there is a lot more going on than just the allow edits, so I want to use a module.) Depending on certain conditions, I want to allow or disallow edits using the module.

    Something like, on the main form:
    Call ModuleName(SubFrm1) (should it be I quotes?)

    Then, in the module:

    ModuleName(FN)

    Expression for changing AllowEdits property of the subform

    Help much appreciated. This is driving me nuts.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    It sounds as though you are trying to create a user defined function to remove locks on a subform. I use the following as a reference for fully qualified names
    http://access.mvps.org/access/forms/frm0031.htm

    At the bottom of the page there is an example
    Forms!Mainform!Subform1.Form!

    Form! is the form object inside the contaier Subform1

    The control you place on the Mainform has a name. The example here shows said control has a name "Subform1".

    As you mentioned
    Forms!Mainform!Subform1.Form!.AllowEdits = False
    will remove the edits lock for the form.

    What I see you struggling with is changing various subforms' AllowEdits properties from a global position. The way I see it, you are going to have to write code to include the various control names. I use form locks all the time. I call them from the parent/main form and hard code the control name within the VBA. I never approached it dynamically before.

    The one exception is when I assign different forms to the same subform container. The subform container's control source changes. The subform container's name stays the same. It is the same container with a different form object. So the dynamic is the form object, not the control/container. Still have to code the name.

    The only thing I am imaging now (to create a UDF) is some code to iterate the collection of forms/controls and get the name of the appropriate control that way.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    A subform/subreport is created by installing a subform/subreport container control on another form/report. The container control SourceObject can be a table, query, form, report. I always name the container different from the object it holds, like ctrDetails or as in my example code, ctrSections.

    Since this container control holds a form, the code I used that works references the container name (passed by variable) followed by .Form.

    The function I tested requires the name of the main form and the container control to be passed to it. No reason to use the Screen.ActiveForm method.

    Yes, the literal names need to be in quotes when calling the procedure (sub or function) as shown in my example.
    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.

  6. #6
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    So far, what I think you are telling me, probably because I misinterpret, doesn't work. Simply, what would the code look like for allowEdits control of a subform using a module called from the main form. Could you give me the exact expression to make the item below work?

    Call ModuleName("NameOfSubform")

    Then on the module:
    Public Sub ModuleName(SFN)
    ?????.AllowEdits=false

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    What do you not understand about the working solution offered in post 2? You didn't answer my questions from that post.
    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.

  8. #8
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I thought that I did answer. But the name of the main form Is F_JibPrice. The Sub form is F_Jib_adderDB_SUB. The container? -I seems that I don't know what that means. I do I do know that, in the module, I can insert

    With screen.ActiveForm

    .F_Jib_adderDB_SUB.Form.AllowEdits = True

    and it works. I just need some way to refer to the sub that works.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I offered a way to refer to the sub that works. Have the sub set up to require the mainform name and the subform container control name.

    I also gave an explanation of what the subform container control is.
    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.

  10. #10
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I much appreciate the time and effort that you have spent on this.

    Fact is that my interpretation of your recommendations don't work. It is possible that, because you are very experienced and I got into this on a learn as you go basis, that you are leaving out steps that you take for granted that I know. I was really hoping for someone to just fill out the place where I show question marks on posting 6. In any case, we have both spent a lot of time on this. I am going to ignore the module and put the code in each form. Cluttered, but works. Thanks again for the time.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I did a little more experimenting. This works:

    Screen.Activeform.Controls(SFN).Form.AllowEdits = True

    The SFN variable must be set with the subform container control name. If the control has the same name as the form it holds, then this will still work.
    Last edited by June7; 04-20-2014 at 12:14 AM.
    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.

  12. #12
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    IT WORKS! Thanks so much-I was going nuts. I wasn't aware or even conscious of the need for "Controls" in the expression. I really appreciate how much effort you gave this. Thanks again. SOLVED!

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

Similar Threads

  1. Refer to each line of a subform with a query
    By chacenger in forum Queries
    Replies: 3
    Last Post: 01-05-2014, 12:28 PM
  2. class module vs regular module
    By Madmax in forum Modules
    Replies: 1
    Last Post: 05-01-2012, 03:44 PM
  3. Refer to ONLY THE MONTH??
    By taimysho0 in forum Programming
    Replies: 18
    Last Post: 01-27-2012, 01:12 PM
  4. Replies: 4
    Last Post: 05-16-2011, 04:58 PM
  5. Replies: 1
    Last Post: 04-15-2011, 01:43 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