none
Referencing a textbox on a tab control on main form from a subform RRS feed

  • Question

  • I have a main form with a tab control. The tab control is named 'Screens', with tab pages named pg1, pg2, etc. One of the tab pages has a subform. I am trying to call a value of a textbox on another tab page from within the subform, I keep getting error 424 can not find object.

    my code is

    If me.action = "base line" and me.dtreturn is null and me.resolve = false and me.parent.withdrawldate is null then

    me.parent.status = "Eligible"

    end if

    I am getting the error on the first line. when I hover over the field that exist in the subform, I can see the values, but the ones on the main form do not show the values.

    I tried 'me.parent.Screens.pg3.withdrawldate is null' but still got the error.

    any idea what am i doing wrong?

    Tuesday, February 7, 2017 5:24 AM

Answers

  • I have a main form with a tab control. The tab control is named 'Screens', with tab pages named pg1, pg2, etc. One of the tab pages has a subform. I am trying to call a value of a textbox on another tab page from within the subform, I keep getting error 424 can not find object.

    my code is

    If me.action = "base line" and me.dtreturn is null and me.resolve = false and me.parent.withdrawldate is null then

    me.parent.status = "Eligible"

    end if

    I am getting the error on the first line. when I hover over the field that exist in the subform, I can see the values, but the ones on the main form do not show the values.

    I tried 'me.parent.Screens.pg3.withdrawldate is null' but still got the error.

    any idea what am i doing wrong?

    If the text box in question is on a tab page, and not on a subform on that page, then referring to it from the subform with "Me.Parent.<name of text box>" should work.  Have you checked the spelling of the control name?  You wrote:

        me.parent.withdrawldate

    Should that be:

        me.parent.withdrawaldate

    ?

    What do you get in the Immediate window if you enter:

        ?Forms!<your main form name>.withdrawldate

    ?

    The code you posted can't be a perfect copy/paste from your subform's code module, because some of the keywords would have been capitalized.  So to let us debug it less speculatively, please copy and paste the actual code.

    EDIT: never mind, I just spotted the big error in your code.  You can't use "is null" in VBA code.  You have to use the IsNull() function instead, like this:

        If Me.action = "base line" and IsNull(Me.dtreturn) and Me.resolve = False and IsNull(Me.Parent.withdrawldate) Then


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html


    • Edited by Dirk Goldgar Tuesday, February 7, 2017 6:36 AM
    • Marked as answer by al.sallam Tuesday, February 7, 2017 5:16 PM
    Tuesday, February 7, 2017 6:33 AM

All replies

  • I have a main form with a tab control. The tab control is named 'Screens', with tab pages named pg1, pg2, etc. One of the tab pages has a subform. I am trying to call a value of a textbox on another tab page from within the subform, I keep getting error 424 can not find object.

    my code is

    If me.action = "base line" and me.dtreturn is null and me.resolve = false and me.parent.withdrawldate is null then

    me.parent.status = "Eligible"

    end if

    I am getting the error on the first line. when I hover over the field that exist in the subform, I can see the values, but the ones on the main form do not show the values.

    I tried 'me.parent.Screens.pg3.withdrawldate is null' but still got the error.

    any idea what am i doing wrong?

    If the text box in question is on a tab page, and not on a subform on that page, then referring to it from the subform with "Me.Parent.<name of text box>" should work.  Have you checked the spelling of the control name?  You wrote:

        me.parent.withdrawldate

    Should that be:

        me.parent.withdrawaldate

    ?

    What do you get in the Immediate window if you enter:

        ?Forms!<your main form name>.withdrawldate

    ?

    The code you posted can't be a perfect copy/paste from your subform's code module, because some of the keywords would have been capitalized.  So to let us debug it less speculatively, please copy and paste the actual code.

    EDIT: never mind, I just spotted the big error in your code.  You can't use "is null" in VBA code.  You have to use the IsNull() function instead, like this:

        If Me.action = "base line" and IsNull(Me.dtreturn) and Me.resolve = False and IsNull(Me.Parent.withdrawldate) Then


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html


    • Edited by Dirk Goldgar Tuesday, February 7, 2017 6:36 AM
    • Marked as answer by al.sallam Tuesday, February 7, 2017 5:16 PM
    Tuesday, February 7, 2017 6:33 AM
  • If me.action = "base line" and me.dtreturn is null and me.resolve = false and me.parent.withdrawldate is null then

    me.parent.status = "Eligible"

    end if

    Hi al.sallam,

    Instead of using  "is null" (in SQL statements) you can better use the  "IsNull" function (in VBA), as in:

    If me.action = "base line" and IsNull(me.dtreturn) and me.resolve = false and IsNull(me.parent.withdrawldate) then
    
    me.parent.status = "Eligible"
    
    end if
    

    Imb.

    Tuesday, February 7, 2017 7:18 AM
  • Hi Dirk,

    Thank you for your response. you are right, I did not copy and paste from the actual code, I tried to simplify it, however, here is the exact code:

    If Me.Pt_QAction = "Pt Baseline Questionnaire" And Me.QDateSent Is Not Null And Me.Pt_QDateReturned Is Null And Me.Pt_ActionResolved = False And _  Me.Parent.Pt_WithdrawlDate Is Null And Me.Parent.Pt_OffStudyDate Is Null And Me.Parent.Pt_DeathDate And Me.Parent.Randomization Is Null Then     Me.Parent.Pt_Status = "Pt Baseline is Pending" End If

    ‘Pt_WithdrawlDate’ is the name of this field (without the a). it was a typo that was realized later. not worth the correction now since it was used in so many places in db.

     

    let me clarify my structure:

    1-    Main form that has a tab control with multiple pages (tabScreens)

    2-    the subform is on one of the pages of (tabScreens) tab control, lets call it pg3

    3-    this code is behind one of the textboxes on the subform

    4-    the following textboxes are on the tab control on different tab page (pg1):

    ‘Pt_WithdrawlDate’, 'Pt_OffStudyDate', 'Pt_DeathDate'

    5-    The following field is not on the tab control but it is on the main form

    'Randomization'

    6-    The following fields are on the subform:

    ‘Pt_QAction’ , ‘QDateSent’, ‘Pt_QDateReturned’ , ‘Pt_ActionResolved’

    --------------------------------------------------------

    When I entered ?Forms!frmrecruiting.Pt_WithdrawlDate

    In the immediate window (while form was running), I got ‘Null’ value, which is correct. So, I am not sure how can I reference these textboxes on the tab page.

    Tuesday, February 7, 2017 4:39 PM
  • qUICK update,

    the following seems to work as per your suggestion:

    If Me.Pt_QAction = "Pt Baseline Questionnaire" And Not IsNull(Me.QDateSent) And IsNull(Me.Pt_QDateReturned) And Me.Pt_ActionResolved = False And _
     IsNull(Me.Parent.Pt_WithdrawlDate) And IsNull(Me.Parent.Pt_OffStudyDate) And IsNull(Me.Parent.Pt_DeathDate) And IsNull(Me.Parent.Randomization) Then
        Me.Parent.Pt_Status = "Pt Baseline is Pending"
    End If

    I am going through the code and correcting it. thank you so much

    Tuesday, February 7, 2017 5:15 PM