Solved VBA sendkeys BACKSPACE

skdn71

New member
Local time
, 00:31
Joined
Jul 23, 2023
Messages
25
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
 
Please define the term, "doesn't work".

What do you expect to happen?

What actually happens instead?
 
SendKeys "{BACKSPACE}" on txtSearch

When Listproduct form open frm frmNav
 
see photo
 

Attachments

  • photo.jpg
    photo.jpg
    46.3 KB · Views: 59
Why not just use
Code:
Me.txtSearch = ""
or
Me.txtSearch = Null
 
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

Back
Top Bottom