473,830 Members | 2,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class

'class module
Public WithEvents clsTxt As TextBox
Private Sub clsTxt_Enter()
clsTxt.BackColo r = VBA.ColorConsta nts.vbCyan
End Sub

'form module
Dim txt(1) As New Class1
Private Sub Form_Load()
Set txt(0).clsTxt = Me.Text0
Set txt(1).clsTxt = Me.Text1
End Sub

i want to change the backcolor of the textbox control when the user
focusing in the textbox control.
but the upper source code doesnot work.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 20 '06 #1
4 2279
I understand you want to change the BackColor of a Control in a Form
displayed in Single Form View to vbCyan when that Control receives the Focus
and revert to its original BackColor when it loses the Focus. If that is
not correct, post back and clarify.

You don't have to get "fancy" with class modules... besides which, I see
nothing to be triggered by the control receiving the focus in yours.

In the General Declarations section of the Form's module, put:

Dim lngSavedColor As Long

Then, still in the General section, add:

Private Function CyanBack()
lngSavedColor = Me.ActiveContro l.BackColor
Me.ActiveContro l.BackColor = vbCyan
Function
Private Function OldBack()
Me.ActiveContro l.BackColor = lngSavedColor
End Function

And in the GotFocus event of each Control where you want this behavior:

= CyanBack()

And in the LostFocus event of each Control where you want the behavior:

= OldBack()

That said, a more common color for highlighting controls would be Yellow, or
Light Yellow, but, I admit, your cyan does show up.

Larry Linson
Microsoft Access MVP
"x taol" <to******@yahoo .comwrote in message
news:45******** *************@n ews.qwest.net.. .
'class module
Public WithEvents clsTxt As TextBox
Private Sub clsTxt_Enter()
clsTxt.BackColo r = VBA.ColorConsta nts.vbCyan
End Sub

'form module
Dim txt(1) As New Class1
Private Sub Form_Load()
Set txt(0).clsTxt = Me.Text0
Set txt(1).clsTxt = Me.Text1
End Sub

i want to change the backcolor of the textbox control when the user
focusing in the textbox control.
but the upper source code doesnot work.

*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '06 #2
On 21 Nov 2006 00:08:15 GMT, x taol <to******@yahoo .comwrote:

I'm not sure I fully follow your code, but it appears you think that
as long as you write the Form_Load code, once Text0.OnEnter occurs,
your code would automatically be called.

That's creative thinking, but it doesn't work like that. Read up on
WithEvents: it only works for ActiveX controls, not for a regular
textbox. Unfortunately Access doesn't have a way to break into the
event model like you want (unlike .Net).

Write your code in the Text0_Enter and Text1_Enter event procedures.
There of course you could call a central function to set the BackColor
and whatever else you want to do.

-Tom.

>'class module
Public WithEvents clsTxt As TextBox
Private Sub clsTxt_Enter()
clsTxt.BackCol or = VBA.ColorConsta nts.vbCyan
End Sub

'form module
Dim txt(1) As New Class1
Private Sub Form_Load()
Set txt(0).clsTxt = Me.Text0
Set txt(1).clsTxt = Me.Text1
End Sub

i want to change the backcolor of the textbox control when the user
focusing in the textbox control.
but the upper source code doesnot work.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '06 #3
You have to arm the objects on the form to run an event procedure when
the Enter event fires. You may want to give the class object a Control
property (any other property name should be fine too) that sets up the
wrapper control to handle the event. Something like:

-Air code, use with caution-

'*********Class module*********
Private WithEvents mTxt as TextBox

Public Property Set Control(txt as TextBox)
Set mTxt = txt
With mTxt
.OnEnter = "[Event Procedure]"
.....whatever other props you want to set....
End With
End Property

Public Property Get Control as TextBox
Set Control = mTxt
End Property

Private Sub mTxt_Enter()
mTxt.BackColor = vbCyan
End Sub

'*********Form declarations*** ******
Private mTxt(1) as TextBox

'*********Form module*********
Private Sub Form_Load()
For i = 0 to 1
Set mTxt(i) = New Class1
Next i

Set mTxt(0).Control = Me.Text1
Set mTxt(1).Control = Me.Text2
End Sub

Private Sub Form_Unload()
For i = 0 to 1
Set mTxt(i) = Nothing
Next i
End Sub

'*********End Code*********

You can obviously still use the Enter event in the form's module, but
remember that any code that runs in the form's module will execute
ahead of the code that executes in the custom class object that it
wraps.

More info here:
http://msdn.microsoft.com/library/de...sesobjects.asp

Nov 21 '06 #4
Works fine, here. I do this sort of thing with all sorts of little
widgets I've set up to do things standard controls don't do.

Tom van Stiphout wrote:
On 21 Nov 2006 00:08:15 GMT, x taol <to******@yahoo .comwrote:

I'm not sure I fully follow your code, but it appears you think that
as long as you write the Form_Load code, once Text0.OnEnter occurs,
your code would automatically be called.

That's creative thinking, but it doesn't work like that. Read up on
WithEvents: it only works for ActiveX controls, not for a regular
textbox. Unfortunately Access doesn't have a way to break into the
event model like you want (unlike .Net).

Write your code in the Text0_Enter and Text1_Enter event procedures.
There of course you could call a central function to set the BackColor
and whatever else you want to do.

-Tom.

'class module
Public WithEvents clsTxt As TextBox
Private Sub clsTxt_Enter()
clsTxt.BackColo r = VBA.ColorConsta nts.vbCyan
End Sub

'form module
Dim txt(1) As New Class1
Private Sub Form_Load()
Set txt(0).clsTxt = Me.Text0
Set txt(1).clsTxt = Me.Text1
End Sub

i want to change the backcolor of the textbox control when the user
focusing in the textbox control.
but the upper source code doesnot work.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9604
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A, while an instance of class C should be able to check all methods #defined in C, B and A. #------------------------------------------------
18
6964
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I guess I'll try to narrow it down to a few specific questions, but any further input offered on the subject is greatly appreciated: 1. Are all of my class's methods supposed to take 'self' as their first arg? 2. Am I then supposed to call...
1
3347
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me to turn a previously made String class that deals with char's into a templated String class that uses the template parameter C instead of char. I thought it would be fairly simple to do this exercise, but I encoutered many errors for my...
13
2397
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes. Two sub-classes have the relationship to communicate back and forth through this pointer. The pointer is responsible inside Top class for allocating and deallocating two sub-classes. CMemory class is responsible to allocate and deallocate memory...
9
4998
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class pointer which points to an instance of a derived class, but when I pass that base class pointer into a function, it can't access the derived object's public functions. Although, the base class pointer does call the appropriate virtual function...
8
2858
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base class is executed. It means that three derived classes are pointed to a separated copy of base class. I do not allow second and third copy of base class to be created, but it must remain only first copy of base class. It allows three derived...
21
4090
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class A { std::vector<B*> Bs; public:
5
3167
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits CommonPageBase - Contains myPage which inherits PageBase Each of these classes overrides OnInit and ties an event handler
3
3763
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and thawed it out. I built a console app using Microsoft Visual C++ 6 (VC++) and it worked great. Only one line in the header file had to be commented out. I built a console app using Borland C++ Builder 5. The linker complained of references to...
0
2841
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass magic, I wrote the following module. It is mainly useful as a light weight tool to help programmers catch mistakes at definition time (e.g., forgetting to implement a method required by the given interface). This is handy when unit tests or...
0
9790
marktang
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...
0
10481
jinu1996
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...
1
10524
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,...
0
9312
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6948
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5616
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...
0
5779
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4409
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
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.