Can I customize a control class?

P

Paul Johnson

I have written the following sub for a textbox control on a form, which
emulates the Shift-F3 key combination in MS Word, cycling through lower,
proper, and upper case for selected text. I may want to use this in several
textboxes, and I know I could put the code in a module and call it from the
textbox controls, but what I would like to do is to create a new textbox
class that inherits from the stock object and adds my method. Is there a
good article for me to learn how to code this?

TIA,
Paul Johnson
------------------------------------------------------
Private Sub Comments_KeyDown(KeyCode As Integer, Shift As Integer)
Dim intCase As Integer, intSelStart As Integer, intSelLength As Integer,
vbCase As VbStrConv
If KeyCode = 114 And Shift = 1 Then ' Shift - F3 pressed
With Comments
vbCase = IIf(Asc(Right(Trim(.SelText), 1)) =
Asc(UCase(Right(Trim(.SelText), 1))), vbLowerCase, _
IIf(Asc(Trim(.SelText)) = Asc(UCase(Trim(.SelText))),
vbUpperCase, vbProperCase))
' "...A" sets it to vbLowerCase, or
' "A..." sets it to vbUpperCase, or
' "a..." (assumed by not "A..") sets vbCase to
vbProperCase
intSelStart = .SelStart
intSelLength = .SelLength ' Need to save selection data
.SelText = StrConv(.SelText, vbCase) ' Convert selection
.SelStart = intSelStart
.SelLength = intSelLength ' Restore selection
End With
End If
End Sub
 
A

Art

Hi Paul,
Check out "Access 2000 Developer's Handbook Vol 1" by
Getz, Litwin and Gilbert. Chapter 3 Page 46. Good
discussion of VBA classes. Maybe something to help you on
your way.

The Easy Day
 
A

Albert D. Kallal

I have written the following sub for a textbox control on a form, which
emulates the Shift-F3 key combination in MS Word, cycling through lower,
proper, and upper case for selected text. I may want to use this in several
textboxes, and I know I could put the code in a module and call it from the
textbox controls,

Yes...why not make a general routine, and specify it in the keydown event.
Trying to build a class here is not going to be much help, as when you place
a text box on the screen..YOU WILL have to decide which text boxes will need
this ability..and which ones do not!

For the above reason (and the fact that you can't create a screen object in
ms-access)...then what do you gain? You can't possibility want the standard
general text box to inherit this property for all text boxes. Having, or
lack of inheritance is moot in this case..since you can't create your own
screen objects anyway! (if we could create our own screen objects..then
inheritance would be big deal..but since we can't create screen
objects..then you gain nothing here).

However, you can certainly create your own re-usable sub-form control with
just one text box on it that looks like a text control. That certainly will
work..and you thus can consider that as your re-useable object with shift-f3
ability built in. This would in effect give you the ability to in effect
create your own custom control. You can read about this idea here:

http://www.attcanada.net/~kallal.msn/Articles/fog0000000005.html

As mentioned, you can create class objects in ms-access...but not screen
objects.

You can read about creating objects in ms-access here:

http://www.attcanada.net/~kallal.msn/Articles/WhyClass.html

As it turns out...if you are using access 2002 and later YOU CAN GET class
objects to consume events!. This is not documented right now in the
help.....but it is cool feature. The only drawback is that about 3-6 lines
of code is needed on the forms load event to "tie" the particular control to
the class object you build. So, if you have two controls..you got a whack of
code in the forms on-load event to "tie" the controls to the class module.
Since you need so much code to do this...AND SINCE you don't really need a
class object..then I can't recommend this approach.

I would either create a custom control (via a sub form), or simply call the
global routine. For most event code you can just place the function name in
the properties sheet like

=MyGolbalEventCode()

That above means for a lot of event code..you don't even have to open he
code module for the form. However, in your case..the keyDown event can't
work..since it requires two parameters to be passed!.

And, last, but not least...if you do want a class module to consume the
events (with that nasy extra code)....then you check out the use of "with
events" in this article.

http://accessadvisor.net/doc/13276
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top