473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

class

'class module
Public WithEvents clsTxt As TextBox
Private Sub clsTxt_Enter()
clsTxt.BackColor = VBA.ColorConstants.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 2264
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.ActiveControl.BackColor
Me.ActiveControl.BackColor = vbCyan
Function
Private Function OldBack()
Me.ActiveControl.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*********************@news.qwest.net...
'class module
Public WithEvents clsTxt As TextBox
Private Sub clsTxt_Enter()
clsTxt.BackColor = VBA.ColorConstants.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.BackColor = VBA.ColorConstants.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.BackColor = VBA.ColorConstants.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
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,...
18
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...
1
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...
13
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....
9
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...
8
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...
21
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...
5
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...
3
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.