[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

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

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?
0
SteveL13
Asked:
SteveL13
2 Solutions
 
Rgonzo1971Commented:
Hi,

Do you want to change the selection?

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

Regards
0
 
Jeffrey CoachmanCommented:
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, ...it has been "clicked".
0
 
SteveL13Author Commented:
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.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
PatHartmanCommented:
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.
0
 
Jeffrey CoachmanCommented:
I agree with Helen, ...you 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...
0
 
hnasrCommented:
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
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now