Value from textbox control in subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcupito
    Contributor
    • Aug 2013
    • 294

    Value from textbox control in subform

    I have a textbox control on a subform and I am trying to get it's text or value into a query. The users are entering a date into this textbox.

    This is how I am referencing the textbox:

    Code:
    [Forms]![AstProfileFrm]![AstProfileWhatIfSbfrm].[Form]![SepDateInputTxt]
    When I reference the textbox in an IIf, it works. If I just try to
    Code:
    SELECT [Forms]![AstProfileFrm]![AstProfileWhatIfSbfrm].[Form]![SepDateInputTxt] AS DateField
    it returns null or empty.

    AstProfileFrm is the Main form.
    AstProfileWhatI fSbfrm is the name of the Sub form.
    SepDateInputTxt is the name of the control

    Does anyone know what's going on here? Or why it may work in the IIf and not elsewhere?
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    You were not clear as to which level you are calling the value from.
    For example in the subform you could use the me![field] construct etc...

    In anycase, I suspect it has to do with from where you are calling the value, honestly when I get stuck, I go back to these two references and I can usually figure out the issue from there:
    Allen Browne: Referring to Controls on a Subform

    Forms: Refer to Form and Subform properties and controls

    Comment

    • mcupito
      Contributor
      • Aug 2013
      • 294

      #3
      So if I am just trying to run a query (not on a particular form or anything), but I am trying to reference controls on a subform, do I use [Forms]![ParentForm]![Subform].[Form]![TextBoxControl] ?

      And then if I were going to run this same query on a button click on that same subform, then it would be Me![TextBoxControl] ?

      Let me clarify a little bit: I have a main form that has a subform area on it. Based on a combobo selection on the main form, different subforms can fill that area.

      This is the code:
      Code:
      SELECT CASE Me![ComboboxTest]
      CASE 1
      Me.ReportSelectSbfrm.SourceObject = "ReportWhatDatesFrm"
      So would I reference it via [Forms]![ParentForm]![ReportSelectSbf rm].Forms![TextBox] ?

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        if the SQL runs within the code of the subform the Me!ctrlin fact all controls and code local to the form can use me!The parent controls can be referenced by parent! / parent. I rarely if ever code the fully qualified control name... always me!/me. for use within the form, parent!/parent.
        In fact on a form with as second subform I've use this:
        parent.SubformC ontainer2.Form. NameOfControlOn TheForm from within SubformContaine r1

        So if you had 6 subforms that fill the subform-container, loaded by the after_update event of your combobox, then each subform can use the parent!/parent. construct to refer the parent form and each subform only need to use me!/me. construct to refer to controls within its own structure.

        HOWEVER,

        if you are referenceing something in/from another form, or the SQL was a stored query then you need the full "qualified path" to the subform container and then the control
        Forms.NameOfPar ent.NameOfSubfo rmContainer.For m.NameOfControl OnTheForm

        SO IIRK:
        say you have a single control named zctrlTxtFilter in all six of your subforms

        Forms.NameOfPar ent.NameOfSubfo rmContainer.For m.zctrlTxtFilte rWould look for the zctrlTxtFilter control on the currently loaded subform in NameOfSubformCo ntainer and return the value of the control.

        AHHH until you hit the ACC2010 navigation control and subforms here's part of control sorce for a calculated control on the subform:
        =(...)[Forms]![frm_navigation]![NavigationSubfo rm].[Form]![sfm_qry_a_i_lb]![h_fk_i](...)
        This is part of a calculated control that returns a value based on another control and because of the IIF() and the nature of the ACC2010-NavCtrl I had to fully qualify the control path.

        now isn't that a hoot-n-a-half!
        Last edited by zmbd; May 20 '14, 10:03 PM.

        Comment

        Working...