By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,967 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,967 IT Pros & Developers. It's quick & easy.

.BackStyle Missing

NeoPa
Expert Mod 15k+
P: 31,709
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) :
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkLocked_AfterUpdate()
  2.     Dim ctl As Object     'Same problem if done As Control
  3.  
  4.     With Me
  5.         .AllowEdits = (Not .chkLocked)
  6.         For Each ctl In .Detail.Controls
  7.             .BackStyle = .chkLocked
  8.         Next ctl
  9.     End With
  10. 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.
Jun 6 '09 #1
Share this Question
Share on Google+
12 Replies


FishVal
Expert 2.5K+
P: 2,653
Hi, NeoPa.

Your code invoke BackStyle property of current form.
Compiler knows that since it knows type of Me object.
Jun 6 '09 #2

100+
P: 675
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.
Jun 6 '09 #3

NeoPa
Expert Mod 15k+
P: 31,709
@FishVal
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 :)
Jun 6 '09 #4

NeoPa
Expert Mod 15k+
P: 31,709
@OldBirdman
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 :)
Jun 6 '09 #5

ADezii
Expert 5K+
P: 8,679
NeoPa makes a valuable point in Post #4, whereas you can programmatically set the BackColor Property of individual Form Sections, as in:
Expand|Select|Wrap|Line Numbers
  1. Forms!Orders.Section(acDetail).BackColor = QBColor(9)
  2. Forms!Orders.Section(acHeader).BackColor = QBColor(10)
  3. Forms!Orders.Section(acFooter).BackColor = QBColor(11)
  4. Forms!Orders.Section(acPageHeader).BackColor = QBColor(12)
  5. Forms!Orders.Section(acPageFooter).BackColor = QBColor(13)
  6.  
Jun 7 '09 #6

NeoPa
Expert Mod 15k+
P: 31,709
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 :
Expand|Select|Wrap|Line Numbers
  1. With Me
  2.     lngColour = IIf(.chkLocked, conEditNo, conEditYes)
  3.     .FormHeader.BackColor = lngColour
  4.     .Detail.BackColor = lngColour
  5.     .FormFooter.BackColor = lngColour
  6. End With
This works fine, but itemising each section like this seems pretty messy to me :(
Jun 7 '09 #7

ADezii
Expert 5K+
P: 8,679
@NeoPa
.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...Controls, TableDef...TableDefs, 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:
    Expand|Select|Wrap|Line Numbers
    1. Dim sec As Section
    2.  
    3. Set sec = Forms!Orders.Section(acDetail)
    4.  
    5. sec.BackColor = QBColor(4)
    6.  
  2. You could also:
    Expand|Select|Wrap|Line Numbers
    1. On Error Resume Next
    2. Dim intSectionCounter As Integer
    3. Randomize
    4.  
    5. For intSectionCounter = 0 To 4
    6.   Me.Section(intSectionCounter).BackColor = QBColor(Int(Rnd * 16))
    7. Next
Jun 7 '09 #8

FishVal
Expert 2.5K+
P: 2,653
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.

Expand|Select|Wrap|Line Numbers
  1. Public Function FormSections(frm As Access.Form) As VBA.Collection
  2.  
  3.     Dim col As New VBA.Collection
  4.  
  5.     On Error Resume Next
  6.  
  7.     For i = 0 To 4             'sections with indexes 0 to 4 are available in form
  8.         col.Add frm.Section(i), frm.Section(i).Name
  9.     Next i
  10.  
  11.     Set FormSections = col
  12.  
  13. End Function
  14.  
Then in form module:
Expand|Select|Wrap|Line Numbers
  1. .....
  2.     For Each obj In FormSections(Me)
  3.         .....
  4.     Next
  5. .....
  6.  
The same function could set Section.Backcolor 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.
Jun 7 '09 #9

ADezii
Expert 5K+
P: 8,679
@FishVal
  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:
    Expand|Select|Wrap|Line Numbers
    1. col.Add frm.Section(i)
  2. And any Reference to these Objects could be obtained via something similar to:
    Expand|Select|Wrap|Line Numbers
    1. Dim obj As Object
    2.  
    3. For Each obj In FormSections(Me)
    4.    Debug.Print obj.Name, obj.BackColor, obj.Height, ...
    5. 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.
Jun 7 '09 #10

FishVal
Expert 2.5K+
P: 2,653
@ADezii
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:
Expand|Select|Wrap|Line Numbers
  1.     Dim col As VBA.Collection
  2.     Set col = FormSections(Me)
  3.  
  4.     Debug.Print col(1).Name
  5.     Debug.Print col("Detail").Name
  6.     Debug.Print col!Detail.Name
  7.  
If collection is for iteration only, then keys are of no use.
Jun 7 '09 #11

NeoPa
Expert Mod 15k+
P: 31,709
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 :)
Jun 7 '09 #12

ADezii
Expert 5K+
P: 8,679
@FishVal
Thanks for the explanation, FishVal. Always a pleasure.
Jun 7 '09 #13

Post your reply

Sign in to post your reply or Sign up for a free account.