mercredi 1 avril 2015

cant get class module to work to change colour of active field

I've created a class module which is used to change the colour of the active field in a user form. The the sub within the module is called I get the error "wrong number of arguments or invalid property assignment".


The class coding us as follows:



Option Explicit

Public Event GetFocus()
Public Event LostFocus()

Private strPreCtr As String

Public Sub CheckActiveCtrl(objForm As MSForms.UserForm)

With objForm
If TypeName(.ActiveControl) = "ComboBox" Or TypeName(.ActiveControl) = "TextBox" Then
strPreCtr = .ActiveControl.Name
MsgBox strPreCtr
On Error GoTo terminate
Do
DoEvents
If .ActiveControl.Name <> strPreCtr Then
If TypeName(.ActiveControl) = "ComboBox" Or _
TypeName(.ActiveControl) = "TextBox" Then
'can only raise events that are declared as Public Events within the Class
RaiseEvent LostFocus(strPreCtr)
strPreCtr = .ActiveControl.Name
RaiseEvent GetFocus(strPreCtr)
End If
End If
Loop
End If
End With

terminate:
Exit Sub

End Sub


I declare the cls in the form activation



Private Sub UserForm_Activate()
Set objForm = New clsCtlColor


and then call the class sub



ActiveControl.BackColor = &HC0E0FF
objForm.CheckActiveCtrl frmNewJob


this is when the error is received. ""wrong number of arguments or invalid property assignment". Any suggestions as to why this is happening would be greatly appreciated.


Aucun commentaire:

Enregistrer un commentaire