Referencing a control from a form in a module

chrisjames25

Registered User.
Local time
Today, 12:31
Joined
Dec 1, 2014
Messages
404
HI.

I am trying to reference the active control in a form in a module but keep getting an error stating control needs to be in active window.

Code:
Dim ctlCurrentControl As Control
Dim strControlName As String

Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name
ctlCurrentControl.ForeColor = vbRed

Instead of screen.activecontrol how could i refernece the current active form?
 
instead of a module cant you put the code into the form? ,and it will KNOW its active.

if you cant put the code in the form, can you send the module code the form ID,:
Code:
'in the form:
Call MyFct(Me)          'send the form id with it

'in the module:
Function MyFct(pfrm as form)
 pfrm.cbobox.backcolor = vbRed
end Function
 
Screen. ActiveForm
 
Another way is to pass the control to the module.

Code:
'Put that in the form
'Call the procedure/sub in the module from the form
Call ActiveControlInForm(Me.ActiveControl)

'Put the following in a module.
Public Sub ActiveControlInForm(ctrl As Control)
   ctrl.ForeColor = vbRed
End Sub
 

Users who are viewing this thread

Back
Top Bottom