Results 1 to 5 of 5

Thread: Key Return is detected in a secondary form

  1. #1

    Thread Starter
    Addicted Member Cristian's Avatar
    Join Date
    Jun 2006
    Posts
    228

    Cool Key Return is detected in a secondary form

    I have a primary form with a MSHierarchical Flexgrid control. when a press the enter key over the MSHierarchical Flexgrid control a secondary form is open.
    The problem is that the enter key is detected by the secondary form and change the focus from the active control.
    My question is how can i delete the keyboard buffer for the secondary form will not get the enter key ?

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Key Return is detected in a secondary form

    Isn't it just a matter of clearing the key before loading the new Form?
    Code:
    Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
    If KeyAscii = Asc(vbCr) Then
        KeyAscii = 0
        Form2.Show
    End If
    End Sub

  3. #3
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Key Return is detected in a secondary form

    And just for the heck of it, throw in a DoEvents, in the line prior to the Form2.show

    Rob
    PS If neither of those fixes you, knock up a tiny project that demonstrates your problem, and attach it for one of us to look at.
    Last edited by Bobbles; Jul 25th, 2013 at 06:37 AM. Reason: Adding a PS

  4. #4

    Thread Starter
    Addicted Member Cristian's Avatar
    Join Date
    Jun 2006
    Posts
    228

    Re: Key Return is detected in a secondary form

    I'd try that you said but still the same. The solution that i found is to declare a public boolean variable called lLoadForm. Then before show the secondary form i set the value to True and at the secondary form, in the KeyUp control event to check the lLoadForm value.

    Like this:

    Private Sub TxtAmount_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn And IsNumeric(TxtAmount.Text) Then
    If lLoadForm = True Then
    lLoadForm = False
    Else
    CmdSave.SetFocus
    End If
    End If
    End Sub

    Thanks for the help to everyone

  5. #5
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Key Return is detected in a secondary form

    Your first post was a bit light on detail.
    It sounds like it was a control focus that was causing (or adding to) the problem.
    My memory is a bit rusty (and old), so I don't fully recall the precise solution.
    However if you add a textbox (or perhaps another control) to your form, and set it's Left property to -999 then it will not be visible.
    Say we call it txtTakeFocus.
    Set it's Tabstop to True and it's TabIndex to 0.
    Now when your Form Loads, the focus can be handled (ignored).
    I have resorted to that to solve more complex problems than the one you described.

    Rob
    Last edited by Bobbles; Jul 25th, 2013 at 08:46 AM. Reason: Changed Index to TabIndex

Tags for this Thread

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