473,387 Members | 1,556 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,387 software developers and data experts.

Access2003 VBA : generic functions

48
I would to know if it is possible to write generic functions to set properties on form.fields

A quick example to show what I mean :

Instead of
Me!FieldA.BackColor = 255
Me!FieldB.BackColor = 255
...

Sort of substitution :
SetBackColor("FieldA")
SetBackColor("FieldB")

Function SetBackColor(Fieldname)
Me!%Fieldname%.BackColor=255
End Function

The %Fieldname% dynamically replaced by FieldA FieldB

The example doesn't make very much sense, it's only purpose is to show the idea.

Are there any possibilities to realize such a solution ?

Thx
Nov 28 '07 #1
3 1685
FishVal
2,653 Expert 2GB
Hi, there.

It looks like you don't like OOP. ;)
Or you just wanted to ask "how can I pass to my function reference to object?"

Anyway I have a good news - reference to object may be passed to sub/function just like any other variable.

Example:
Expand|Select|Wrap|Line Numbers
  1. Public Sub SetBkColor(ByRef txbTarget As Access.TextBox, _
  2.                                   ByVal lngColor as Long) 
  3.     txbTarget.BackColor = lngColor
  4. End Sub
  5.  
then in form module
Expand|Select|Wrap|Line Numbers
  1. SetBkColor Me.txtSomething, 255
  2.  
or taking into account that several control types have BackColor property, something like this

Expand|Select|Wrap|Line Numbers
  1. Public Sub SetBkColor(ByRef objTarget As Variant, _
  2.                                   ByVal lngColor as Long) 
  3.     On Error Resume Next
  4.     objTarget.BackColor = lngColor
  5. End Sub
  6.  
then in form module
Expand|Select|Wrap|Line Numbers
  1. SetBkColor Me.cboSomething, 255
  2.  
Regards,
Fish
Nov 28 '07 #2
wquatan
48
Hi, there.

It looks like you don't like OOP. ;)
Or you just wanted to ask "how can I pass to my function reference to object?"

Anyway I have a good news - reference to object may be passed to sub/function just like any other variable.

Example:
Expand|Select|Wrap|Line Numbers
  1. Public Sub SetBkColor(ByRef txbTarget As Access.TextBox, _
  2.                                   ByVal lngColor as Long) 
  3.     txbTarget.BackColor = lngColor
  4. End Sub
  5.  
then in form module
Expand|Select|Wrap|Line Numbers
  1. SetBkColor Me.txtSomething, 255
  2.  
or taking into account that several control types have BackColor property, something like this

Expand|Select|Wrap|Line Numbers
  1. Public Sub SetBkColor(ByRef objTarget As Variant, _
  2.                                   ByVal lngColor as Long) 
  3.     On Error Resume Next
  4.     objTarget.BackColor = lngColor
  5. End Sub
  6.  
then in form module
Expand|Select|Wrap|Line Numbers
  1. SetBkColor Me.cboSomething, 255
  2.  
Regards,
Fish
Hi Fish,

Sure I like OOP, the problem is that I'm writing a system with a dozen of forms and a huge number of fields, which need all the same formatting and conditional testing. It would be a great waste of time (and resources) to do that over-and-over for any of them.

Thank you very much for your input, it's exactly what I was looking after. Great ! :-)

Greetz
Walter
Nov 28 '07 #3
FishVal
2,653 Expert 2GB
Glad, it helped you.
Good luck and happy coding.
Nov 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jim Newton | last post by:
hi all, i'm relatively new to python. I find it a pretty interesting language but also somewhat limiting compared to lisp. I notice that the language does provide a few lispy type nicities, but...
16
by: Roman Suzi | last post by:
Hi, I wonder, does Python support generic programming paradigm, and to what extent (I guess, it doesn't do it in full)? And (or) does it move in that direction? Will we ever see concept...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.10.2004 Hello, As far as I understand, the generic programming basically consists in using templates for achieving a static polymorphism of the various code fragments, and their...
9
by: Lauren Quantrell | last post by:
Hoping someonce can tell me what compatibility problems I might run into when I have to have my Access Project developed on Access2K run in a user environment where users are using Access2003 as...
9
by: 2D Rick | last post by:
With the help from members in the VB forum I've pieced together code that works in VB6 to create radial text similar to "text on a path" seen in graphics programs.(on a circle only) I use an...
13
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format...
2
by: deependrapathak | last post by:
Hi All, I am currently facing a crutial problem in Access2003 in Windows XP on just 3 PCs, the Application throws some of the errors specified below : 1. Error Number : 3075 Function is not...
3
by: Ramchandar | last post by:
Hi, I am creating reports using VBA code. I have the same query in a querydef residing both in Access97 and Access2003. The result of this querydef is then moved to a table in Access97 and...
26
by: raylopez99 | last post by:
Here is a good example that shows generic delegate types. Read this through and you'll have an excellent understanding of how to use these types. You might say that the combination of the generic...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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.