Results 1 to 7 of 7
  1. #1
    Remster is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2010
    Posts
    317

    Comparison of subform controls

    The following VBA code evaluates to True if MyControl is a text box but False if MyControl is a subform control:



    Code:
    MyForm!MyControl Is MyForm.Controls("MyControl")
    What is the correct syntax for comparing subform controls?

    Edit: I've just discovered that MyForm!MyControl Is MyForm!MyControl and MyForm.Controls("MyControl") Is MyForm.Controls("MyControl") also evaluate to False if MyControl is a subform control!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,528
    why do you need to compare subforms? Are you not interested in the data in them?

  3. #3
    Remster is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2010
    Posts
    317
    Not in the context from which I've abstracted my example. Since you ask, I'm looping through all the controls on MyForm and changing the Painting property of all the subforms other than MyControl.Form. Something like this:

    Code:
    Dim Ctrl As Control
    For Each Ctrl in MyForm.Controls
    If Ctrl.ControlType = acSubForm And Not Ctrl Is MyForm!MyControl Then Ctrl.Form.Painting = False
    Next Ctrl
    Last edited by Remster; 12-10-2020 at 10:45 AM. Reason: Correction

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,815
    Try Forms!FormNameHere.SubformControlNameHere
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Remster is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2010
    Posts
    317
    Already tried it. Same problem! Of course, I can compare the subforms themselves rather than the subform controls, but I don't understand why that would be necessary.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,119
    You are not showing us where /how you set MyControl. I would try something like this:
    Code:
    Dim Ctrl As Control,MyControl as Control
    
    set MyControl=Me.ActiveControl 'or any other reference to a form control
    
    For Each Ctrl in MyForm.Controls
        If Ctrl.ControlType = acSubForm And Ctrl.Name <>MyControl.Name Then Ctrl.Form.Painting = False
    Next Ctrl
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    Remster is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2010
    Posts
    317
    Thanks, that works too, with judicious naming.

    For the record, 'MyControl' in my code sample was just a placeholder for the control's name.

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

Similar Threads

  1. Working with Subform controls
    By dweekley in forum Access
    Replies: 3
    Last Post: 05-05-2017, 10:23 AM
  2. Replies: 3
    Last Post: 04-29-2017, 12:09 PM
  3. Referencing subform controls
    By cheyanne in forum Forms
    Replies: 7
    Last Post: 04-30-2012, 10:00 AM
  4. How to add controls on subform
    By rashima in forum Forms
    Replies: 1
    Last Post: 04-01-2012, 06:16 AM
  5. subform controls
    By donnan33 in forum Forms
    Replies: 30
    Last Post: 02-27-2012, 09:06 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