Results 1 to 2 of 2

Thread: Command Button set as Default Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    49

    Unhappy Command Button set as Default Problem

    Here's a strange one (at least to me). What the following code is supposed to do is set the mousepointer to the hourglass when the user clicks on the cmdSearch button, set the mousepointer back to default, give the focus to the txtCompanyNumber text box, and select the text in the txtCompanyNumber text box. I have the .Default property of the cmdSearch button set to true to please the anti-mouse-using-data-entry-users. Everything works find if I actually click the cmdSearch button. However if I hit the Enter key the mousepointer does not change and the text in the txtCompanyNumber text box does not get selected. If I step through the code, it all gets executed, and the value of the mousepointer is correct. But it won't change under normal usage. I've played with form refreshes, changing screen to the name of the form, DoEvents, etc. But I can't get it to work. Does anyone know why this is? I know I can trap the enter key and achieve the same results, but it'd be nice if this worked.

    VB Code:
    1. Private Sub cmdSearch_Click()
    2.     Screen.MousePointer = vbHourglass
    3.     UpdateRecordset BuildSQLText
    4.     cmdFirst.Enabled = True
    5.     cmdPrevious.Enabled = True
    6.     cmdNext.Enabled = True
    7.     cmdLast.Enabled = True
    8.     cmdVoucher.Enabled = True
    9.     cmdViewInvoice.Enabled = True
    10.     dgInvoice.Enabled = True
    11.     Screen.MousePointer = vbDefault
    12.     txtCompanyNumber.SetFocus
    13.    
    14. End Sub
    15.  
    16. Private Sub txtCompanyNumber_GotFocus()
    17.     txtCompanyNumber.SelStart = 0
    18.     txtCompanyNumber.SelLength = Len(txtCompanyNumber.Text)
    19.    
    20. End Sub

    Thanks,

    Leecher

  2. #2
    Hyperactive Member
    Join Date
    May 2003
    Posts
    401
    COpy and paste the code in Command_Click event into Command_Keypress event in between the following :

    If keyascii =13 then
    'Copy ur command_click event code here.
    End If

    Keyascii 13 is for enter key and this code gets invoked when u press enter key. However retain the code in the Mouse_Click event also for Mouse activities. This should help. Try and see.
    Enjoy!!!
    apps_tech

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width