Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125

    Code for Disabling sub form until a field in the parent form is Not Null

    I am developing a DB and I am faced a problem in one of my forms. The form name is FrmSales. It contains a subform named "frmSalesSubform".




    The problem is that when i start entering data in the subform before going to the parent form, by the time i go to the parent form, the data in the sub form disappears and updates the table.


    What i want is a code that can force the subform to be inactive until a field in the parent form is Not Null.

    Thanks in advance.

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    Thanks Pbaldy but this does not actually solve the problem.

    The link is only referring to Controls on a form. But this one concerns a control and a subform.
    The subform should be inactive until the control (Say "CustomerName") has been filled.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Quote Originally Posted by Demerit View Post
    The link is only referring to Controls on a form. But this one concerns a control and a subform.
    What is the subform contained within? A subform control on the main form. That control can be disabled just like a textbox.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    The main form is titled "FrmStockTransferOut" and the subform is tittled "FrmStockSubform" and the controls are:FrmStockTransferOut BranchId StockID (The link control) DateOfEntryFrmStockSubform ProductName Unit Quatity StockID (The link control)

  6. #6
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125

    Here is the way they are structured

    The parent form is tittled "FrmStockTransferOut" and the subform is tittled "FrmStockSubform" with the following contols

    FrmStockTransferOUt
    BranchID
    StockID (link to child field)
    DateOfEntry

    FrmStockSubform
    ProductName
    Unit
    Quantity
    StockID

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Have you tried it? My previous may have been confusing, as it wasn't really a question I was looking for an answer to. Perhaps this clarifies my intent better:

    Question: What is the subform contained within?
    Answer: A subform control on the main form. That control can be disabled just like a textbox.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125

    Below is the sample of the db

    Here attached is the section am talking about:
    This is the code i just added behind the form on the Before update event but its not working.


    If Me.BranchID Is Null Then
    Me.ProductName.Visible = False
    Me.Quantity.Visible = False
    M.Unit.Visible = False
    Me.UnitCost.Visible = False
    Else
    Me.ProductName.Visible = True
    Me.Quantity.Visible = True
    M.Unit.Visible = True
    Me.UnitCost.Visible = True
    End If




    SubformDisable.zip

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I'm not sure the before update event of the form is appropriate. As discussed in the link, I'd use the current event of the form and the after update event of the BranchID combo (perhaps a function called by each so the code is only in one place).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    By the way, you're setting controls on the subform, so the syntax is wrong. Try this:

    Me.FrmStock2Subform.Visible = Not IsNull(Me.BranchID)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    I have tried the code but the subform remains invisible even after entering the BrandID

  12. #12
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Did you put it where I suggested? I did, and it worked as expected.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    I entered the code on the On Current event of the form FrmStockTransferOut

  14. #14
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    Could help me with an upload of yours?

  15. #15
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Here you go.
    Attached Files Attached Files
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-03-2013, 01:20 PM
  2. Insert drop-down list in Parent Field in a form
    By Haleakala17 in forum Forms
    Replies: 7
    Last Post: 09-11-2012, 07:20 PM
  3. Replies: 3
    Last Post: 10-03-2011, 02:33 PM
  4. Replies: 1
    Last Post: 08-11-2011, 06:22 AM
  5. Replies: 2
    Last Post: 10-19-2010, 11:05 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