Public Module/Function

S

Silvio

Hello, I am trying to setup a public function/module that will re-format the
typed text once the user tabs over to the next field in form (convert CAP
lowercase etc to Title Case). I used to enter the following code in
AfterUpdate in each field in my database: Street = StrConv(Street,
vbProperCase). However, I am re-designing the database and it make more sense
to me to create something public that I can call from any form and field (as
long is a text field) in my database. I never done this and I need help in
setup such module correctly and how to attach/call it from applicable fields
in forms. Keep in mind that all my text fields have different name, not all
are called "Street", some is Street, some is notes etc. Please be as specific
as you can because I am not a pro.

Thank you for your help.
 
D

Douglas J. Steele

Easiest option would be to have a function like:

Function FixCase()
Screen.PreviousControl = _
StrConv(Screen.PreviousControl, vbProperCase)
End Function

Then, in the LostFocus event of all of the text boxes where you want to fix
the text, put =FixCase()

(make sure you put the = sign and parentheses)
 
S

Silvio

Thank you Steele, the only problem I incountere is that I named the Module
FixCase and by enterig =FixCase() on lost focus the system was unable to find
the module, then I renamed the module to FixCase() and it works fine.

Thank you.
Silvio
 
D

Douglas J. Steele

Modules cannot have the same name as functions or subs contained within
them.
 
K

Klatuu

You do not call the name of a module. You call the name of the function
within the module. A module should not have the name of any Subs or
Functions in it. Proper naming practices will prevent this problem. Modules
should be prefixed with either bas or mod. For example, either basFixCase or
modFixCase. The the function should be named FixCase. It should be a Public
functions. When you type in
Public Function FixCase
It will convert (before your very eyes) to
Public Function FixCase()
The () is not included in the name.
Correct this problem, and the code that Douglas J. Steele provided will work
for you.
 
S

Silvio

But the system was able to operate properly only after I renamed the module
to read FixCase()
 
K

Klatuu

That is because you had a funtion in the module with the same name. Once you
added (), the module name is no longer the same as the function name.
Using the ( or ) in any name in Access is a bad idea.
Never use any special characters or a space in any name. Use only Letters,
Numbers, and the Underscore _
Never use an Access reserved word (Date, Year, Month, Name, etc.) as a name.
It will confuse Access. If you follow proper naming conventions, you will
not have name conflict problems.

Here is a site that will help.

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp

Now, change the name module to modFixCase. You function will still work and
you will be in compliance.

If you don't follow our advice, we will come to your house and spill
disgusting things on your carpet :)
 

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