In the past I’ve called subs and functions (stored in regular old modules) from user forms. I do this because quite often I’ll have a piece of code that will run in many user forms, for example to create user initials based on the name typed in, to populate common comboboxes, etc. Quite often my sub or function will require parameters, such as the user form it is being called from, or the control it should affect, etc. as these are required in the code, but may vary depending on the user form I want the code to affect.
This has always worked very simply in the past…up to Word 2003 that is. Now, for some reason I can’t seem to get these same pieces of code to work. They worked in Word 2002, but when I brought the code into Word 2003, no go. However, if I put the code as a sub IN the user form, the code works just ducky. But I don’t want to put all this code in all my user forms, I want to just be able to call it as needed and keep it in one place.
Following is a sample bit of code that works fine if placed in the User Form, but doesn’t work if I call it (although, remember, it used to work in Word 2002).
Public Sub PopInitials(objForm As Object)
‘Populates Initials with the first letter of each word in the Name
On Error GoTo RoutineErr
Dim sName As String
Dim sInitials As String
Dim nCount As Integer
‘If name is changed, recreates initials based on first letter of each word
sName = objForm.cboAuthor.Value
Do Until InStr(1, sName, ” “) = 0
sInitials = sInitials & Left(sName, 1)
sName = Right(sName, Len(sName) – InStr(1, sName, ” “))
Loop
sInitials = sInitials & Left(sName, 1)
objForm.txtInitials.Value = sInitials
RoutineExit:
Exit Sub
RoutineErr:
clsErrorHandler.AssertError “basPopControls.PopInitials”
Resume RoutineExit
End Sub
Does anyone have any ideas as to what has changed or what I have to do to make this work?
As always, your help is invaluable,
Karina