How trigger a click on a text box when the form opens

Posted on 2014-08-08
Last Modified: 2014-08-11
I have a form that opens and a text box is the focus.  But I want to somehow trigger or force a click on that text box.  What would the code be for doing this?
Question by:SteveL13
    LVL 47

    Expert Comment


    Do you want to change the selection?

    Private Sub Form_Open()
        Me.txtMyBox.SelStart = 0
        Me.txtMyBox.SelLength = 0
    End Sub
    'EDIT OR
    'Do you mean?
    Private Sub Form_Open()
    End Sub

    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    I think he first expert has your sluton...
    If not, then pleas clearly define "Trigger/Force a click"
    ...You want to force a user to click the box?
    If the textbox has the focus, then programmatically, has been "clicked".

    Author Comment

    No.  I just want to force a click on the textbox.  (simulate a click on it).

    I have other code firing if the textbox is clicked.  I just want it to be clicked without manually having to click it.
    LVL 33

    Accepted Solution

    You need to better define when you want this to happen.
    Do you want it to happen only ONCE when a form opens or do you want it to happen each time the user navigates to a new record?  Or do you want it to happen for only certain records?

    Rather than trying to force a click in a checkbox, just run the code from the form's Load event (run once on open) or from the form's Current event (run for each record you navigate to).  You would use the Current event if you want to trigger the code for certain records but you would make it conditional.

    Then, if you want to give the user the option of manually running the code also, use a button rather than a checkbox.  Buttons are the visual trigger to "do" something.
    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    I agree with Helen, can put code on the Click event, ...but you cannot "trigger" a click event in code...

    Can we ask why this is needed, ...perhaps there is a better way...
    LVL 30

    Assisted Solution

    Try: Not sure if it is that simple, and I guess this why Jeffrey is inquiring about the purpose.

    Private Sub Form_Load()
        txtBox_Click ' this runs the code in click event of txtBox control
    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now