Results 1 to 10 of 10
  1. #1
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11

    obtain a value of a control present in a tabbed subform

    Good evening,
    I'm working on a new mask disconnected from all the others.

    I created the variable (as string) IdentifyMyProg. This string must take the value of a text box present in my sub-form.

    The sub-form (chil form) is called m_AU and is inserted into one of the tabs/pages present in the parent form m_AA_AB

    The text box is called ProgrAUT. The tab/page should be called TabCtl121.Pages(2).

    I tried to copy the value of ProgrAUT into the variable.



    I tried several instructions without success. Here some examples:

    Code:
     
    IdentifyMyProg = [Forms]![m_AA_AB]![m_AU]![ProgrAUT]
    IdentifyMyProg = Forms![m_AA_AB]![m_AU].Form![ProgrAUT]
    IdentifyMyProg = [forms]![m_AA_AB]!TabCtl121.Pages(2)![ProgrAUT]
    IdentifyMyProg = [Forms]![m_AA_AB]!TabCtl121.Pages(2).Form![ProgrAUT]
    IdentifyMyProg =Forms!m_AA_AB!m_AU.Form!ProgressivoAUT.Value
    Thanks for your answers

  2. #2
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Shortcut:
    Open m_AU form in design mode > Properties > Other > Has Module Yes or True, whatever it is
    IdentifyMyProg = Form_m_AU.ProgrAUT

    Dot notation:
    Open main form in design mode and find the name of the subform control that holds your subform. If the name of the subform control is the same as the name of the subform, then:
    IdentifyMyProg = Forms.m_AA_AB.Form.m_AU.Form.ProgrAUT
    If the name of the subform control is another, then:
    IdentifyMyProg = Forms.m_AA_AB.Form.YourSubformControlName.Form.Pro grAUT

    No need to reference the tab.
    Please click on the ⭐ below if this post helped you.


  3. #3
    Join Date
    Apr 2017
    Posts
    1,681
    The info in your post is not detailed enough (Is the subform continuous or single one, must the value of control originate from active row of subform, or from some fixed row, or is the control there unbound one?), but in case you want the value of control for active row in subform, maybe this way is much easier:
    Into main form, add an unbound control (text box) for wanted value, and hide it.
    In subform, in OnCurrent and AfterUpdate events, update the value of hidden unbound control in main/parent form with value of wanted control in this subform.

    I myself use this technique to connect cascading subforms (the 2nd subform displays records linked to active row in 1st subform, where both of them are continuous ones, and they both are inserted directly into main form), but you also always can refer to this hidden control from any event in your main form.

  4. #4
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11
    i've controlled in my m_AU form (in design mode > Properties > Other > and it had Module Yes)

    So I've used your code:
    IdentifyMyProg = Form_m_AU.ProgrAUT

    and it works fine!

    Thanks

    PS. I've tried also the others instructin but they don't works

  5. #5
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Quote Originally Posted by ArviLaanemets View Post
    Into main form, add an unbound control (text box) for wanted value, and hide it.
    In subform, in OnCurrent and AfterUpdate events, update the value of hidden unbound control in main/parent form with value of wanted control in this subform.

    I myself use this technique to connect cascading subforms (the 2nd subform displays records linked to active row in 1st subform, where both of them are continuous ones, and they both are inserted directly into main form), but you also always can refer to this hidden control from any event in your main form.
    PMFJI.
    The unbound textbox technique originates from misusing Master/Child link properties, and it's understandable why this confusion may arise. Typically, when referencing properties in the properties pane or a query, the instinct is to begin with Forms!/Forms. or Form!/Form. However, with Master/Child link properties, the current form is already provided. Therefore, all that's required is to append the remaining details.
    This is why you can directly use the unbound textbox name as a reference, as the main form is already given. So, how do you do it? For instance, if your main form contains a subform control named "SubformControl0," then in the Master/Child link properties, you would write for the master this:
    Code:
    SubformControl0.Form.FieldID
    And for the child, just:
    Code:
    FieldID
    As the form in the subform control is also given in that context.
    Please click on the ⭐ below if this post helped you.


  6. #6
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Quote Originally Posted by MF_PA View Post
    i've controlled in my m_AU form (in design mode > Properties > Other > and it had Module Yes)

    So I've used your code:
    IdentifyMyProg = Form_m_AU.ProgrAUT

    and it works fine!

    Thanks

    PS. I've tried also the others instructin but they don't works
    Cool, I'm glad it works now. As for those that didn't work, that comes from the fact that I don't know your exact setup. Luckily, the shortcut eliminates that problem.
    Please click on the ⭐ below if this post helped you.


  7. #7
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11
    Good morning again,
    I'm having a problem with the code

    Code:
    IdentifyMyProg = Form_m_AU.ProgrAUT
    a bug opens when the variable IdentifyMyProg must take the value of a text box present in the Form_m_AU.ProgrAUT when this subform is not opened (not showed) in the parent form.
    I tried the following instructions without success:
    Code:
    If Nz(Form_m_AU.ProgrAUT, 0) = 0 Then
    IdentifyMyProg = "T"          ‘ T as true
     Else: IdentifyMyProg = Form_m_AU.ProgAUT
    End If 
    other code tried:
    Code:
    If [Forms]![m_AA_AB]!TabCtl121.Pages(2).Visible = True Then
    IdentifyMyProg = Form_m_AU.ProgrAUT 
     Else: IdentifyMyProg = "F"          ‘ F as false
    'End If 
    Thanks for your answers

  8. #8
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11
    i've solved but using another way

    i've setted a new variable VerifyFirst
    VerifyFirst = Nz(DLookup("[ProgrAUT]", "AU", "[CIUProv]= '" & me.CIUProv & "'AND " & "[IstatProv]= '" & me.IstatProv & "'"), "false")

    If VerifyFirst<> "falso" Then

    ....
    else
    ....
    end if

    But i'm interessed to understand why
    my code does not run
    If Nz(Form_m_AU.ProgrAUT, 0) = 0 Then
    IdentifyMyProg = "T" ‘ T as true
    Else: IdentifyMyProg = Form_m_AU.ProgAUT
    End If

  9. #9
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    There is a lot to explain there. But I suspect it is the fact that ProgrAUT can be a value or a textbox. When used in the context of a DLookup, it's a value. But within your code it is not very well specified. This is why it's best:
    1. to use Option Explicit at the top of the module,
    2. having well declared variables,
    3. knowing you're comparing apples to apples, and
    4. knowing objects have default members.


    Without a sample file, without seeing the error you get and without knowing your setup, we can only assume, but here's a few insights:
    1. You can only reference an open form using dot syntax (Forms.FormControl.Form.FormControl, or Forms!FormControl.Form!FormControl)
    2. You can bypass the full reference to a form by using the Form_formName.FormControl syntax, but if the form is not loaded, it will load it. That means you can only have one instance of this form open and that it should be opened, otherwise you may get weird results.
    3. The VBA language is flexible with its developers. You can happily compare a textbox to a string or a number, but you can also happily compare it to an object, so you must understand and make sure you're comparing apples with apples.
    4. Tabs serve no essential purpose for referencing; they simply manage the visibility of controls already loaded. Consequently, you can access any control within a tab in the same manner as if they were not within a tab.
    5. Subform controls are controls that let you embed forms inside forms. You must take them into account when using dot syntax.
    6. Subform controls have a member called Form, this member lets you access the things inside the form that is holding.
    7. The DLookup function always assumes that, if you're using a textbox as a reference within it, you're referring to its value, not its textbox nature.
    Please click on the ⭐ below if this post helped you.


  10. #10
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11
    [QUOTE=Edgar;522876]
    thanks Edgar,
    Your answer will help me to correct misunderstanding code, in order to correctly compare
    apples with apples.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-11-2020, 02:09 PM
  2. Form order control of Tabbed Documents
    By BlindSquirrel in forum Forms
    Replies: 9
    Last Post: 02-21-2017, 09:55 PM
  3. tabbed control with combo boxes
    By vicsaccess in forum Forms
    Replies: 13
    Last Post: 12-15-2015, 11:43 AM
  4. Replies: 1
    Last Post: 10-06-2015, 06:50 AM
  5. Replies: 12
    Last Post: 12-13-2011, 04:04 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