0
votes

I am using this code to set the focus on the end of the text box in a form but I can only do so if I set the focus to that text box which is at the middle of my form. I have setup tab control and I want the focus to be at the first text box.

My code is:

        Me.txtBox.Locked = True
        Me.txtBox.SetFocus
        Me.txtBox.SelStart = Len(Me.txtBox.Text)

I tried add this after the code above to set the focus to first text box again.

pfPositionCursor Me.txtBox1

But I get sub or function undefined on pfPositionCursor

Is there a way to do something like this?

1
If you don't have a procedure named pfPositionCursor then of course you can't call it. Also, "placing the cursor" in a TextBox means that the next Input from the keyboard will be at that position, and as that is in that TextBox , the TextBox has the focus. For controls, "having the focus" and "the next keystroke affects this control" are equivalent.Wolfgang Kais
What event is this code in? I use Click, Enter, GotFocus of the control to be acted on. Can't input to a locked control.June7
This code is on onOpen form eventjedu

1 Answers

0
votes

You can pass a control in a function for example:

Call ControlFocusFunction(Me!MyTextbox)


Public Function TextBoxFocusFunction(ctlControl as Control)

  If ctlControl.ControlType = acTextBox Then

    ctlControl.SetFocus
    ctlControl.SelStart(Len(ctlControl.Text))

  End If

End Function