I was getting an error on the below line:
X = 1 * (Instr(Ctrl.Name, "InputCent") + 1 * instr(Ctrl.Name, "InputEur") + 1 * Instr(Ctrl.Name, "Enabled") + 1 * Instr(Ctrl.Name, "Cancel") + 1 ' (X resolves in this case to = 1)
So I made it:
X = 1 * ((InStr(Ctrl.Name, "InputCent") + 1) * (InStr(Ctrl.Name, "InputEur") + 1) * (InStr(Ctrl.Name, "Enabled") + 1) * (InStr(Ctrl.Name, "Cancel") + 1))
Was also getting an error on the below lines:
.Controls ("tb" & Mid(Ctrl.Name, 3 Len(Ctrl.Name) - X) & "InputEur").Enabled = True
.Controls ("tb" & Mid(Ctrl.Name, 3 Len(Ctrl.Name) - X) & "InputEur"). SetFocus '!!! This line throws up the Error (BTW the ActiveControl at this point
So I made them:
.Controls("tb" & Mid(Ctrl.Name, 3, Len(Ctrl.Name) - X) & "InputEur").Enabled = True
.Controls("tb" & Mid(Ctrl.Name, 3, Len(Ctrl.Name) - X) & "InputEur").SetFocus '!!! This line throws up the Error (BTW the ActiveControl at this point turned out to be "cbClose", the CommandButton which steers the shutdown of the UDF.)
May not fix your error but looked as if it needed correcting, your full code below wrapped in code tags (for others to look at)
Sub CancelInput(Ctrl As Control)
Ctrl.Name = "frSky"
Ctrl.Enabled = False
Dim X As Long
X = 1 * ((InStr(Ctrl.Name, "InputCent") + 1) * (InStr(Ctrl.Name, "InputEur") + 1) * (InStr(Ctrl.Name, "Enabled") + 1) * (InStr(Ctrl.Name, "Cancel") + 1))
With Userform3
If InStr(Ctrl.Name, "Input") > 0 Then '(it is in fact greater than nought)
.Controls("tb" & Mid(Ctrl.Name, 3, Len(Ctrl.Name) - X) & "InputCent") = ""
.Controls("tb" & Mid(Ctrl.Name, 3, Len(Ctrl.Name) - X) & "InputEur") = ""
' The string in brackets resolves into "tbSkyInputEur", which is the correct name of the targeted textbox
ElseIf InStr(Ctrl.Name, "Elements") > 0 Then '(which it isn't)
'irrelevant code
End If
.Controls("tb" & Mid(Ctrl.Name, 3, Len(Ctrl.Name) - X) & "InputEur").Enabled = True
.Controls("tb" & Mid(Ctrl.Name, 3, Len(Ctrl.Name) - X) & "InputEur").SetFocus '!!! This line throws up the Error (BTW the ActiveControl at this point turned out to be "cbClose", the CommandButton which steers the shutdown of the UDF.)
.lbInputErr.Visible = False
.lbInputErr.Caption = "INPUT BLOCKED: "
End With
End Sub