Results 1 to 6 of 6

Thread: [RESOLVED] help keypress "VbkeyReturn"

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    6

    Resolved [RESOLVED] help keypress "VbkeyReturn"

    im making a simple login form,
    i want to use the keypress,
    when i enter my username and password and hit the enterkey,
    the form2 will appear and also the msgbox if the username and password,is wrong.this what i have,but is not working,pls help what is worng or what should i do...tanx
    Code:
    Private Sub Command1_Click()
    If Text1.Text = "aaa" And Text2.Text = "111" Then
    Form2.Show
    Unload Me
    Else
    MsgBox "wrong"
    Text1.SetFocus
    Text1.Text = ""
    Text2.Text = ""
    End If
    Form1.KeyPreview = True
    End Sub
    
    Private Sub Command1_KeyPress(KeyAscii As Integer)
    Select Case KeyCode
    Case vbKey13
    Call Command1_Click
    End Select
    End Sub
    Last edited by RobDog888; Oct 6th, 2009 at 08:00 PM. Reason: Added [code] tags

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: help keypress "VbkeyReturn"

    Welcome to the Forums.

    Set the KeyPreview property of your Form1 from your property grid window instead of at runtime in the command1_click event, it will be too late to receive the prop change at that time.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: help keypress "VbkeyReturn"

    u can set the command button default property = true, then if u press enter, command_click event wil be executed.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: help keypress "VbkeyReturn"

    Quote Originally Posted by jhamez
    Private Sub Command1_KeyPress(KeyAscii As Integer)
    Select Case KeyCode
    Case vbKey13
    Call Command1_Click
    End Select
    End Sub[/code]
    There is no KeyCode in a KeyPress event.
    Code:
    Private Sub Command1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
         Command1.Value = True
    End If
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    6

    Re: help keypress "VbkeyReturn"

    tanx for d help....

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: help keypress "VbkeyReturn"

    We are glad to have helped.

    Ps, dontforget to mark your thread as Resolved from the Thread Tools so others will know your question has been answered.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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