Results 1 to 15 of 15
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    If statment on SubForm

    Hi all,


    I need some help please.
    I have a form (frmAccount) and on it has Several sub forms with tabs to change to different sub forms.
    The Subform is (sfrmAccount) On Form
    By clicking tabs, it changes the soruce object to different subforms.
    The sub form i have the Lbl on is (sfrmAccountDetail)
    The sub form that has the (IsPaid check Box) is (sfrmTransBill) and is a data sheet.

    What i am trying to do is if a bill in (sfrmTransBill) is not ticked then I want a lable to appear in the (sfrmAccountDetail)
    That says Payment Due (LblPayment)
    I cant figure out how to access the (IsPaid) in (sfrmTransBill) to allow this lbl to appear in (sfrmAccountDetail)

    Code:
    If Forms!sfrmAccount.sfrmTransBill.Form.IsPaid = False Then
    Me.LblPayment.Visible = True
    Else
    Me.LblPayment.Visible = False
    End If
    I would beleive I would put the code in On Current of (sfrmAccountDetail)?

    Thank you for any help on this
    Dave
    Last edited by d9pierce1; 11-14-2021 at 01:33 PM. Reason: clairification

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Assumes you are using a Tab control not a Navigation Form.

    Reference subform via the subform container name, not the actual form name. I always name container different from the object it holds, like ctrTransBill and and ctrAccount and ctrAccountDetail.

    If this code is behind one subform referencing another subform, then need to also reference through the main form. Can use Me.Parent.

    Me.Parent.ctrTransBill.Form.IsPaid

    If sfrmTransBill is a subsubform sitting on subform sfrmAccount:

    Me.Parent.ctrAccount.Form.ctrTransBill.Form.IsPaid

    If you want to provide db for analysis, follow instructions at bottom of my 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.

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi June7
    Thank you for responding. I used the following and received error like before....
    "Application-Defined or Object-Defined Error"

    Code:
    If Me.Parent.ctrAccount.Form.ctrTransBill.Form.IsPaid = True Then
        Me.LblPayment = True
    Else
        Me.LblPayment = True
    End If
    I really dont want to send up the db as it has all my log in, passwords, and accounts info init. Just to much to get rid of.

    I am not using a typical tab control on parent form. It is basically a subform control, and i use vba to switch the tabls Which are actually buttons.
    Code for that is:
    Code:
    Option Compare Database
    Option Explicit
    Dim TabOffColor As Long
    
    
    
    
    
    
    Private Sub CmdPayNow_Click()
    
    
    If Not IsNull(Me.sfrmAccount.Form.BillID) Then
    DoCmd.OpenForm "frmTransBill", , , "[BillID]=" & Me.sfrmAccount.Form.BillID
    Else
    MsgBox "Please Select a Record to Continue"
    End If
    
    
    End Sub
    
    
    
    
    
    
    
    
    
    
     Sub Form_Open(Cancel As Integer)
        
        TabOffColor = RGB(37, 189, 80)
        
    End Sub
    
    
    
    
    
    
    Sub SwitchTabs(TabName As String, FormName As String, FocusField As String)
        
        
        DoCmd.Echo False
        DoCmd.GoToControl "AccountName"
        SetAllTabsOff
        sfrmAccount.SourceObject = FormName
        Me.Controls(TabName).BackColor = sfrmAccount.Form.Section(0).BackColor
        Me.Controls(TabName).ForeColor = RGB(0, 0, 0)
        DoCmd.GoToControl "sfrmAccount"
        DoCmd.GoToControl FocusField
        DoCmd.GoToRecord , , acFirst
        DoCmd.Echo True
    
    
    End Sub
    
    
     Sub SetAllTabsOff()
    
    
        CmdAccountDetail.BackColor = TabOffColor
        CmdAccountDetail.ForeColor = RGB(255, 255, 255)
        CmdCard.BackColor = TabOffColor
        CmdCard.ForeColor = RGB(255, 255, 255)
        CmdReward.BackColor = TabOffColor
        CmdReward.ForeColor = RGB(255, 255, 255)
        CmdProtection.BackColor = TabOffColor
        CmdProtection.ForeColor = RGB(255, 255, 255)
        CmdViewPayBill.BackColor = TabOffColor
        CmdViewPayBill.ForeColor = RGB(255, 255, 255)
        
    End Sub
     Sub CmdAccountDetail_Click()
        SwitchTabs "CmdAccountDetail", "sfrmAccountDetail", "AccountNumber"
        Me.CmdPayNow.Visible = False
    End Sub
     Sub CmdCard_Click()
        SwitchTabs "CmdCard", "sfrmCreditDebit", "cboCreditDebitType"
        Me.CmdPayNow.Visible = False
    End Sub
     Sub CmdReward_Click()
        SwitchTabs "CmdReward", "sfrmReward", "AccountName"
        Me.CmdPayNow.Visible = False
    End Sub
     Sub CmdProtection_Click()
        SwitchTabs "CmdProtection", "sfrmProtectionPlan", "cboPlanType"
        Me.CmdPayNow.Visible = False
    End Sub
    Private Sub CmdViewPayBill_Click()
    SwitchTabs "CmdViewPayBill", "sfrmTransBill", "BillType"
    Me.CmdPayNow.Visible = True
    End Sub
    Thanks
    Dave

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You have to use your names, June7's were examples, plus both sides of the statement now resolve to true? and no visible property mentioned?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Click image for larger version. 

Name:	screenshot1.jpg 
Views:	17 
Size:	126.6 KB 
ID:	46662Click image for larger version. 

Name:	screenshot2.jpg 
Views:	18 
Size:	123.2 KB 
ID:	46663

    Here are the form design if that helps

  6. #6
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I tried this also and got an method or user defined error? Compile error

    Code:
    If Me.frmAccount.sfrmAccount.Form.sfrmTransBill.Form.IsPaid = False Then
        Me.LblPayment.Visible = True
    Else
        Me.LblPayment.Visible = False
    End If

  7. #7
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Quote Originally Posted by Welshgasman View Post
    You have to use your names, June7's were examples, plus both sides of the statement now resolve to true? and no visible property mentioned?
    I tried it with my names also and got a compile error. Have no idea why either.... but did resolve the True issue....
    thanks,
    dave

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You could simplify it to
    Me.lblPayment.Visible = Not YourBooleanControlName
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Having worked on OP's previous postings, I think the setup is this:
    There is no tab control.
    The "tabs" are command buttons.
    The subform is a single subform control.
    The "tabs" click events load various subforms into the subform control.

    This emulates a Navigation control on a form, along with the problem of intersubform communication.

  10. #10
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Correct davegri

    So with that said, i will not be able to complete this task?
    Thanks

  11. #11
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi davegri,
    | thought about that and it makes sense. The form actually isnt on the page so really hard to access it.
    I guess i could go though back door in a qry to pass the values to it. I will work on it but thanks for
    the insite. I hadnt though of it that way and really made sense of it all.
    Thanks again,
    I will mark this solved
    Dave

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Would have to save value to a global variable or TempVars or a textbox on main form then it could be referenced by next subform loaded.
    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.

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Or OpenArgs?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Well, can't pass OpenArgs to a subform.
    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.

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Quote Originally Posted by June7 View Post
    Well, can't pass OpenArgs to a subform.
    My thinking was to "pull" not pass. Since button clicks are setting the sourceobject, I figured the button click could set that property in the main form then when the subform loads, check its value and set any property as required. Turns out OpenArgs is read only so a button click can't set it. An open/load subform event could read a hidden textbox on the main form which holds the value as set by main form button though.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. iF THEN VBA STATMENT
    By GCLIFTON in forum Queries
    Replies: 16
    Last Post: 07-15-2016, 02:43 PM
  2. if statment
    By ismailkhannasar in forum Access
    Replies: 3
    Last Post: 01-31-2013, 06:48 AM
  3. if statment or case statment?
    By whojstall11 in forum Forms
    Replies: 4
    Last Post: 07-09-2012, 01:44 PM
  4. Like statment
    By brew in forum Programming
    Replies: 2
    Last Post: 12-01-2011, 03:23 AM
  5. SQL statment structure
    By oss_ma in forum Programming
    Replies: 1
    Last Post: 05-13-2007, 02:08 AM

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