Results 1 to 13 of 13
  1. #1
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162

    Control subform textbox from Master form checkbox

    My bound master form has bound subform in it and both of them has linked fields. In the master form i've placed a checkbox which if unchacked will lock and disable a textbox in the SUBFORM, and if checked will enable and unlock the textbox and fill it with a calculation result, which will then be passed on to the underlying table.
    Now, suppose in the master form (named X), i have A (checkbox) and B (textbox with numeric value) and in the subform (named Y), i have C & D (both textboxes with numeric values). Hence if A is checked, I'd like D to return the result of - "B*C". Or else D will remain locked and disabled. Is this possible?

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Here is an Example: Of course change names to match yours. Main form is based on a query with both tables linked.
    If Me.AChkBox = True Then
    [frmY].[Form]![Dtextbox] = Me.Total
    [frmY].[Form]![Dtextbox].Enabled = False

    Me.Dirty = False
    Else
    [frmY].[Form]![Dtextbox].Enabled = True
    End If

  3. #3
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Dear burrina, I have place the code but not working:
    Code:
    Private Sub Form_Current()
    If Me.A= True Then
    Y.Form!D.Enabled = True
    Y.Form!D = Me.B * Y.Form!C
    Else
    Y.Form!D.Enabled = False
    Y.Form!D.Dirty = False
    End If
    End Sub
    May be I can not REFER the subform properly.

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Are those the actual names of the controls and forms? Adjust your code to reflect the example I posted.

  5. #5
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    The database is still in experimental stage and for the sake of simplicity they are the actual names. Please point me if anything is out of sync in the code. I SUSPECT I HAVE MISSED THE WAY I SHOULD REFER TO SUBFORM. Please let me know.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I think burrina's code should work. What happens - error message, wrong results, nothing?

    However, suggest you name the subform container control different from the object it holds, like: ctrY. Then:

    Me.ctrY.Form.D.Enabled = True

    Also suggest using meaningful names and establishing a good naming convention. That way if you like the results don't have to go back and totally rebuild.
    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.

  7. #7
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    It says "compiler error. variable not defined" and highlights the Y in the 3rd line of the code blue.
    Please check my code. Y is the name of the subform within the master form.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Actually, just realized burrina's code is missing something. Correct syntax would be:

    Forms!mainformname.subformContainerName.Form.contr olname.Enabled

    or

    Me.subformContainerName.controlname.Enabled

    Review post 6 again.
    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.

  9. #9
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Yes. The problem was with referencing the subform. Along with this I've also found another workaround by placing the code in the subform's class module. That way i refered the subform controls with Me! and master controls with Form(0). I have added another two more lines of code which would return the D value to null if A is unchecked:
    Code:
    Me.D = Null
    Me.D.Locked = True
    Also removed a line of code from burrina:
    Code:
    Me.Dirty = False
    However there is still a problem. All of these code takes effect once i move to next record. IS THERE A WAY, WHICH WILL INSTANTLY SHOW THE OUTPUT OF "D" DEPENDING ON CHECKED/UNCHECKED STATUS OF "A" WHILE I'M IN THE SAME RECORD?

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Code in the AfterUpdate or Click event of checkbox.
    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.

  11. #11
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    The code I posted was NOT air code, it was tested and worked. Only the names and Events for the code being fired needed to be changed. As to the Me.Dirty = False
    If you prefer to not save it after the change, that is up to you. I'm sure my setup and yours were not the same.

    Good Luck With Your Project!

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Yeah, took another look and your code should have worked.
    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
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Dear burrina,
    the fact is that your code required the Forms! collection and Masterform reference to work with. Anyway, thanks for the help. However, would you care to clarify me the "Me.Dirty = False" statement, it looks like the form is still saving the changes without it.
    Dear June,
    it worked accordingly after I put it in the checkbox afterUpdate event. Thanks a lot for the help and advice.

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

Similar Threads

  1. Replies: 1
    Last Post: 03-21-2014, 06:17 AM
  2. Replies: 2
    Last Post: 01-08-2014, 05:18 PM
  3. Issues with subform and master form
    By asmith533 in forum Forms
    Replies: 14
    Last Post: 09-24-2012, 09:13 AM
  4. Checkbox in mainform to control subform
    By revned12 in forum Forms
    Replies: 3
    Last Post: 09-09-2012, 02:32 AM
  5. subform to open form w/ active master record
    By spitfire122 in forum Access
    Replies: 1
    Last Post: 06-28-2011, 04:28 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