How to declare this variable

systemx

Registered User.
Local time
Tomorrow, 07:44
Joined
Mar 28, 2006
Messages
107
Hi all,

EDITED...

My OnClick event for a number of textboxes (when entering customer info in an unbound form) attempts to position the cursor -

Dim ctlCurrentControl As Control
Dim MyCtrl As String
Set ctlCurrentControl = Screen.ActiveControl
MyCtrl = ctlCurrentControl.Name

'Textbox is empty, position cursor at start
If IsNull(MyCtrl) Or Len(MyCtrl) = 0 Or MyCtrl = "" Then
MyCtrl.SelStart = 0
Else
'Textbox is not empty, position cursor at end of text
Dim MyLen As Integer
MyLen = Len(MyCtrl)
MyCtrl.SelStart = MyLen
End If

It seems that where there is an input mask on the cell, even if the cell is otherwise empty it reads this as having 'something' in the cell - but does not correctly position the cursor regardless. If there is no input mask in the cell, nothing seems to happen at all.

This code worked perfectly before I tried to make it work for any control on the form - when I explicitly mention the control (eg. Me.MyControl) it works correctly.

Can anyone tell me where I am going wrong?

EDIT:

The code below is working, however still not calling where there is no input mask -

Private Sub PositionControl()
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl

If IsNull(ctlCurrentControl) Or Len(ctlCurrentControl) = 0 Or ctlCurrentControl = "" Then
ctlCurrentControl.SelStart = 0
Else
Dim MyLen As Integer
MyLen = Len(ctlCurrentControl)
ctlCurrentControl.SelStart = MyLen
End If

End Sub

EDIT 3:

I am an idiot.

I had hardcoded onclick events without assigning them through the control properties - hence they were not being called. Code works perfectly.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom