Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repetitive code...how to create into a global module 2

Status
Not open for further replies.

KENTOY

MIS
Jan 31, 2003
9
PH
Hi,

I'm quite a beginner in access/vba/vb code, so please bear with me... Anyways i have forms that have this repeating code

Code:
Sub ActiveControl_Enter()
    With Me.ActiveControl
        .Properties("BorderStyle") = 1
        .Properties("BorderWidth") = 2
        .Properties("BorderColor") = vbRed
    End With
End Sub

Sub ActiveControl_Exit()
    With Me.ActiveControl
        .Properties("BorderStyle") = 1
        .Properties("BorderWidth") = 1
        .Properties("BorderColor") = 0
    End With
End Sub

Which are called by the controls enter and exit event, anybody can help me make this a global function/sub which can be called anywhere in any form.

thanks,
ken
 
Hello:

For global code, you what to create a module and place your code there. Then it can be seen anywhere in your project.

In the VBA editor area select Insert, Module and follow the directions.

Regards
Mark
 
How are ya KENTOY . . .

Copy your code to a module in the modules. Then delete the code in all other places.

Next in the proper event your going to use:
Call ActiveControl_Exit
or
ActiveControl_Enter

Calvin.gif
See Ya! . . . . . .
 
I suggest to pass the Form object as parameter and not use the Me object in a standard module ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi guys, i created my module using the code below

Code:
Sub ActiveControl_Enter(frm As Form)
On Error GoTo Err_ActiveControl_Enter

    With frm.ActiveControl
        .Properties("BorderStyle") = 1
        .Properties("BorderWidth") = 2
        .Properties("BorderColor") = vbRed
    End With

Exit_ActiveControl_Enter:
    Exit Sub
  
Err_ActiveControl_Enter:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Exit_ActiveControl_Enter

End Sub

But when calling this one in the control's enter event i get a "argument not option error" using this

Code:
Call ActiveControl_Enter

anybody? appreciate it,
ken
 
You need to pass the form name
Code:
Call ActiveControl_Enter(frmFormName)
 
CaptainD is correct, this should work:
Code:
Call ActiveControl_Enter([red]Me[/red])
HTH,

Ken S.
 
Thanks CaptainD and Eupher, it worked... maybe its too much caffeine.
 
Thats what [blue]PHV[/blue] said 4 posts from the top! . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top