Using a generic routines...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
B

Brad Pears

I am attempting to write a very generic routine and can;t quite seem to gewt
one part of it as "generic" as I'd like.

In the code I am referring to a specific "control" which may be differnt
from screen to screen. I am trying to write the code "generically" so that I
can call the same code from any screen.

Here is the line of code....

' Turn the font green to show the current process
Forms![frmPricing]![frmMenuItems].Form.cmdGEFraming.ForeColor = 32768


How could I write a function that uses the mainform name, subform name, and
appropriate command button name (as detailed above) that was passed to it
and then runs the code to actually set the color??

Please note that this is just one line that needs to be generalized. I have
many like this that I would like to have in one function/procedure and just
call it from each form that needs it...


The procedure would be something like this I would think...

' Call procedure to set the appropriate values
Call SetFormValues("Mainformname", "SubFormName", "ControlName",
"ForeColor", 32768)

Sub SetFormValues(strMain as string, strSub as string, strControl as string,
strProperty as string, PropertyValue as variant)
dim StrCommand as string

' Concatenate the string command
strCommand = "Forms![" & strMain & "]![" & strSub & "].form." & strControl &
"." & strProperty & "= " & PropertyValue

' I tried using "runcommand" (as show below) but it gives me a "Type
Mismatch"
docmd.runcommand(strCommand)

end sub


' Now that I have the command string concatenated, how do I run it??

Any help would be most appreciated!


Thanks,

Brad
 
Brad,
Can you pass in the controls as a parameter when you call ur routine
instead of string?
Sub SetFormValues(strMain as form, strSub as form, strControl as textbox,
strProperty as string, PropertyValue as variant)


Jeff
 
Consider taking it easy on yourself. Pass the object itself:
Call SetControlValues(Me.Controls(ControlName), "ForeColor", 32768)

Sub SetControlValues(ctl as Control, strProperty as string,
PropertyValue as variant)
ctl.Properties(strProperty) = PropertyValue

If you actually need to change some Form values, create a 2nd routine:

Call SetFormValues(Me, "BackColor", 32768)

Sub SetFormValues(frm as Form, strProperty as string, PropertyValue as
variant)

You might be able to combine these into a more generic
Sub SetObjectValues(obj as Object, etc, etc)
but the drawbacks would be greater than any advantages gained, IMO.

HTH,
 
Back
Top