.BackStyle Missing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #1

    .BackStyle Missing

    I have a project I'm working on where I want to disable editing on a form in certain circumstances. To avoid confusing the operator, I would like to change the appearance of the form so that is visually different between the two modes. A sort of visual clue if you like.

    I developed the following code, but I find that this won't compile (to my surprise) :
    Code:
    Private Sub chkLocked_AfterUpdate()
        Dim ctl As Object     'Same problem if done As Control
    
        With Me
            .AllowEdits = (Not .chkLocked)
            For Each ctl In .Detail.Controls
                .BackStyle = .chkLocked
            Next ctl
        End With
    End Sub
    The error message is "Method or data member not found" and the .BackStyle on line #7 is highlighted (yellow).

    Does anyone have any explanation? I have checked various of the controls (TextBox; Label; ComboBox; CheckBox) and only CheckBox doesn't have this property.
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hi, NeoPa.

    Your code invoke BackStyle property of current form.
    Compiler knows that since it knows type of Me object.

    Comment

    • OldBirdman
      Contributor
      • Mar 2007
      • 675

      #3
      Why not change the form's .BackColor ? I use 3 colors 1)View, 2)Edit, 3)New/Adding to provide this visual clue. I use another set of 3 colors if form is filtered, to avoid frustration of not finding a record that is known to exist.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        Originally posted by FishVal
        Your code invoke BackStyle property of current form.
        Compiler knows that since it knows type of Me object.
        It seems kicking myself is a recurring theme today :(

        At least it got me to look at why the Form object doesn't have such a property (I expected it should). It turns out that the various sections of the form (Header; Detail; Footer; etc) have the property (which shows the colour of the form if - as in my case - they are always set the same).

        Thanks for being a reliable pair of eyes Fish :)

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          Originally posted by OldBirdman
          Why not change the form's .BackColor ? I use 3 colors 1)View, 2)Edit, 3)New/Adding to provide this visual clue. I use another set of 3 colors if form is filtered, to avoid frustration of not finding a record that is known to exist.
          I'm giving this some careful consideration OB.

          It's always harder to change direction midstream, but this idea seems to have such promise that I may take it up (or a version of it at least). With my character unfortunately, it pretty well means revisiting all my old code to bring those up to spec. I may get away without the third colour, but I also like your filtering idea.

          I will have to go away and cogitate on it for a bit.

          Thank you for this idea :)

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            NeoPa makes a valuable point in Post #4, whereas you can programmaticall y set the BackColor Property of individual Form Sections, as in:
            Code:
            Forms!Orders.Section(acDetail).BackColor = QBColor(9)
            Forms!Orders.Section(acHeader).BackColor = QBColor(10)
            Forms!Orders.Section(acFooter).BackColor = QBColor(11)
            Forms!Orders.Section(acPageHeader).BackColor = QBColor(12)
            Forms!Orders.Section(acPageFooter).BackColor = QBColor(13)

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32669

              #7
              Indeed ADezii, but unfortunately the .Section property, even though it appears to be an array or collection, does not seem to support the For ... Each construct.

              Any tips or clues on that one would be helpful. My current code includes :
              Code:
              With Me
                  lngColour = IIf(.chkLocked, conEditNo, conEditYes)
                  .FormHeader.BackColor = lngColour
                  .Detail.BackColor = lngColour
                  .FormFooter.BackColor = lngColour
              End With
              This works fine, but itemising each section like this seems pretty messy to me :(

              Comment

              • ADezii
                Recognized Expert Expert
                • Apr 2006
                • 8834

                #8
                Originally posted by NeoPa
                Indeed ADezii, but unfortunately the .Section property, even though it appears to be an array or collection, does not seem to support the For ... Each construct.

                Any tips or clues on that one would be helpful. My current code includes :
                Code:
                With Me
                    lngColour = IIf(.chkLocked, conEditNo, conEditYes)
                    .FormHeader.BackColor = lngColour
                    .Detail.BackColor = lngColour
                    .FormFooter.BackColor = lngColour
                End With
                This works fine, but itemising each section like this seems pretty messy to me :(
                .Section property, even though it appears to be an array or collection, does not seem to support the For ... Each construct.
                1. The For...Each Construct requires that you iterate through various Objects contained within their respective Collection, usually the plural of the Object's Name (Control...Cont rols, TableDef...Tabl eDefs, etc.). Unfortunately, to the best of my knowledge, a Sections Collection does not exist, ergo (you like that?), you cannot iterate a Collection that simply isn't there. Here is syntax, however, that you use:
                  Code:
                  Dim sec As Section
                  
                  Set sec = Forms!Orders.Section(acDetail)
                  
                  sec.BackColor = QBColor(4)
                2. You could also:
                  Code:
                  On Error Resume Next
                  Dim intSectionCounter As Integer
                  Randomize
                  
                  For intSectionCounter = 0 To 4
                    Me.Section(intSectionCounter).BackColor = QBColor(Int(Rnd * 16))
                  Next

                Comment

                • FishVal
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2656

                  #9
                  Oh, ye. Access object model doesn't have any method or property which gives reference to "Sections" collection.
                  Sure it could be easily obtained with a simple reusable global function like the following.

                  Code:
                  Public Function FormSections(frm As Access.Form) As VBA.Collection
                      
                      Dim col As New VBA.Collection
                      
                      On Error Resume Next
                      
                      For i = 0 To 4             'sections with indexes 0 to 4 are available in form
                          col.Add frm.Section(i), frm.Section(i).Name
                      Next i
                      
                      Set FormSections = col
                      
                  End Function
                  Then in form module:
                  Code:
                  .....
                      For Each obj In FormSections(Me)
                          .....
                      Next
                  .....
                  The same function could set Section.Backcol or in accordance with additional argument(s) and/or global settings and/or predefined form properties.

                  Ultimately, if high level of tuneability is required, then it could be implemented as custom class or a part of existing (if existing) class extending Access.Form class functionality.

                  Comment

                  • ADezii
                    Recognized Expert Expert
                    • Apr 2006
                    • 8834

                    #10
                    Originally posted by FishVal
                    Oh, ye. Access object model doesn't have any method or property which gives reference to "Sections" collection.
                    Sure it could be easily obtained with a simple reusable global function like the following.

                    Code:
                    Public Function FormSections(frm As Access.Form) As VBA.Collection
                        
                        Dim col As New VBA.Collection
                        
                        On Error Resume Next
                        
                        For i = 0 To 4             'sections with indexes 0 to 4 are available in form
                            col.Add frm.Section(i), frm.Section(i).Name
                        Next i
                        
                        Set FormSections = col
                        
                    End Function
                    Then in form module:
                    Code:
                    .....
                        For Each obj In FormSections(Me)
                            .....
                        Next
                    .....
                    The same function could set Section.Backcol or in accordance with additional argument(s) and/or global settings and/or predefined form properties.

                    Ultimately, if high level of tuneability is required, then it could be implemented as custom class or a part of existing (if existing) class extending Access.Form class functionality.
                    1. Hell FishVal, I'm just confused on 1 point so kindly point me in the right direction. If I understand you correctly, the Public Function is returning a Collection of Form Section Objects, so couldn't Line #8 above simply be:
                      Code:
                      col.Add frm.Section(i)
                    2. And any Reference to these Objects could be obtained via something similar to:
                      Code:
                      Dim obj As Object
                      
                      For Each obj In FormSections(Me)
                         Debug.Print obj.Name, obj.BackColor, obj.Height, ...
                      Next
                    3. I thank you in advance for your explanation in this matter.
                    4. Very interesting and informative Comments, as is always the case from you.

                    Comment

                    • FishVal
                      Recognized Expert Specialist
                      • Jun 2007
                      • 2656

                      #11
                      Originally posted by ADezii
                      1. Hell FishVal, I'm just confused on 1 point so kindly point me in the right direction. If I understand you correctly, the Public Function is returning a Collection of Form Section Objects, so couldn't Line #8 above simply be:
                        Code:
                        col.Add frm.Section(i)
                      Hello, ADezii.

                      The 2nd argument of VBA.Collection. Add method is a text key which could be used instead of positional index in a way we are accustomed to.

                      ex:
                      Code:
                          Dim col As VBA.Collection
                          Set col = FormSections(Me)
                          
                          Debug.Print col(1).Name
                          Debug.Print col("Detail").Name
                          Debug.Print col!Detail.Name
                      If collection is for iteration only, then keys are of no use.

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32669

                        #12
                        I appreciate the suggestions chaps.

                        As my desire is to keep the code simpler, I wouldn't go to the extent of writing a class for this, but the numeric indexes in a loop would be a technique that's preferable to my usage of specific names.

                        Neither is as tidy as the For ... Each though. I'm not sure why that is not provided by default. It seems quite inconsistent with all the other objects and collections available.

                        PS. For ... Each can also be used in simple arrays (I found out quite recently). Another reason why I found the lack of support for this in .Section curious.

                        Thanks for all suggestions anyway :)

                        Comment

                        • ADezii
                          Recognized Expert Expert
                          • Apr 2006
                          • 8834

                          #13
                          Originally posted by FishVal
                          Hello, ADezii.

                          The 2nd argument of VBA.Collection. Add method is a text key which could be used instead of positional index in a way we are accustomed to.

                          ex:
                          Code:
                              Dim col As VBA.Collection
                              Set col = FormSections(Me)
                              
                              Debug.Print col(1).Name
                              Debug.Print col("Detail").Name
                              Debug.Print col!Detail.Name
                          If collection is for iteration only, then keys are of no use.
                          Thanks for the explanation, FishVal. Always a pleasure.

                          Comment

                          Working...