Solved VBA sendkeys BACKSPACE (1 Viewer)

skdn71

New member
Local time
Today, 06:04
Joined
Jul 23, 2023
Messages
22
Please help me if I run the VBA below with form_load on the Listproduct form it works fine but if I run it from frmNav on Load_form Listproduct form it doesn't work



Code:
Private Sub Form_Load()
    ' Select the text in the textbox
    Me.txtSearch.SetFocus
    Me.txtSearch.SelStart = 0
    Me.txtSearch.SelLength = Len(Me.txtSearch.Text)
    
    ' Simulate a backspace key press
    SendKeys "{BACKSPACE}"
End Sub
 

GPGeorge

George Hepworth
Local time
Yesterday, 21:04
Joined
Nov 25, 2004
Messages
1,980
Please define the term, "doesn't work".

What do you expect to happen?

What actually happens instead?
 

skdn71

New member
Local time
Today, 06:04
Joined
Jul 23, 2023
Messages
22
SendKeys "{BACKSPACE}" on txtSearch

When Listproduct form open frm frmNav
 

skdn71

New member
Local time
Today, 06:04
Joined
Jul 23, 2023
Messages
22
see photo
 

Attachments

  • photo.jpg
    photo.jpg
    46.3 KB · Views: 21

Gasman

Enthusiastic Amateur
Local time
Today, 05:04
Joined
Sep 21, 2011
Messages
14,423
Why not just use
Code:
Me.txtSearch = ""
or
Me.txtSearch = Null
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:04
Joined
Feb 19, 2002
Messages
43,457
I'm not sure the purpose of the code. You should NEVER dirty a record in the load event and if this is an unbound control, it will always be null when the form opens so you would never have to clear it.
 

Users who are viewing this thread

Top Bottom