NeoPa 32,579
Recognized Expert Moderator MVP
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) : - 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.
12 4544 FishVal 2,653
Recognized Expert Specialist
Hi, NeoPa.
Your code invoke BackStyle property of current form.
Compiler knows that since it knows type of Me object.
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.
NeoPa 32,579
Recognized Expert Moderator MVP @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 :)
NeoPa 32,579
Recognized Expert Moderator MVP @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 :)
ADezii 8,834
Recognized Expert Expert
NeoPa makes a valuable point in Post #4, whereas you can programmaticall y set the BackColor Property of individual Form Sections, as in: -
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)
-
NeoPa 32,579
Recognized Expert Moderator MVP
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 : -
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 :(
ADezii 8,834
Recognized Expert Expert @NeoPa
.Section property, even though it appears to be an array or collection, does not seem to support the For ... Each construct.
- 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:
-
Dim sec As Section
-
-
Set sec = Forms!Orders.Section(acDetail)
-
-
sec.BackColor = QBColor(4)
-
- You could also:
- On Error Resume Next
-
Dim intSectionCounter As Integer
-
Randomize
-
-
For intSectionCounter = 0 To 4
-
Me.Section(intSectionCounter).BackColor = QBColor(Int(Rnd * 16))
-
Next
FishVal 2,653
Recognized Expert Specialist
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. -
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: -
.....
-
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.
ADezii 8,834
Recognized Expert Expert @FishVal - 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:
- And any Reference to these Objects could be obtained via something similar to:
- Dim obj As Object
-
-
For Each obj In FormSections(Me)
-
Debug.Print obj.Name, obj.BackColor, obj.Height, ...
-
Next
- I thank you in advance for your explanation in this matter.
- Very interesting and informative Comments, as is always the case from you.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steven T. Hatton |
last post by:
If you happen to have Accelerated C++ by Koenig and Moo, and haven't gotten
around to reading it, I suggest you count the pages between page 18 and
page 51. I came up with zero. This is very disappointing since I have
been intending to read the book for some time now. I finally picked it up
with the expectation that I would breeze through it as a review and an
alternative expert perspective on C++. Now it looks as though I will have
to...
|
by: Corepaul |
last post by:
Missing Help Files
When I enter "recordset" as the keyword and search the Visual Basic Help index,
I get many topics of interest in the resulting list. But there isn't any
information available from clicking on many of the available topics (mostly
methods but some properties are also unavailable). This same problem occurs
with many, if not most, keywords.
Is there any way I can activate these "missing" help topics? HELP!
|
by: Skybuck Flying |
last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C
compilers produce so many error messages as soon as a closing bracket is
missing. The response was simply because the compiler can't tell where a
bracket is missing.... a few weeks have past, I requested a feature for the
delphi ide/editor "automatic identation of code in begin/end statements etc"
and today when I woke up I suddenly released a very simple solution for this...
|
by: kris |
last post by:
hi can any one help me out,
i have written a code for Word Indexing using Dll's
i think this is an incomplete code for WORD INDEX.
I had encountered this error
"Error! No index entries found" when i opened word document
can any one fill out the missing code with this.
|
by: Justin Emlay |
last post by:
I'm hopping someone can help me out on a payroll project I need to
implement.
To start we are dealing with payroll periods. So we are dealing with an
exact 10 days (Monday - Friday, 2 weeks).
I have a dataset as follows (1 week to keep it short):
Employee 1 - Date 1
Employee 1 - Date 2
| |
by: JD |
last post by:
Is it possible to have a clear backstyle for a lable
control? I want to write some text on a lable and I want
the background of the label to match the color of the
control I am placing the label on where the color of that
control will be changing will be changing. Is this
doable? If not, is there a control I can do this with? to
have a clear/see through backstyle?
Thanks,
JD
|
by: youth |
last post by:
I am trying to bind the DB2 utlities to a new database that was created
by our DBAs. Each time I try I get the following:
db2ajgrt.bnd - No errors
db2clish.bnd - 13 errors all for missing package SQLABD01
db2clisn.bnd - 13 errors all for missing package SQLABD01
db2clibh.bnd - 13 errors all for missing package SQLABD01
db2clibn.bnd - 13 errors all for missing package SQLABD01
db2cliv2.bnd - 2 errors both for missing package SQLABD01...
|
by: Fred Chateau |
last post by:
Still working on my XML DataSet...
Having moved on past difficult and complex problems, resolved with the
assistance of everyone here, I find myself facing yet another problem. My
XML document breaks the schema. There are missing tags everywhere, on
purpose I'm told, because we don't need them.
I'm getting a "System.Data: There is no row at position <row number>" error.
Hopefully I can workaround this issue. I need to find a way to...
|
by: Wayne |
last post by:
The tab control "backstyle" property refuses to work when set to
"transparent" in an A2003 database if Windows themes controls are
being used. I've seen references to this in a few places, but no
fix. If the A2003 database is opened using A2007 the property works
fine. Go figure. Does anyone know of a workaround?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |