Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger code Combo_Ckick() with "Enter-Key" 2

Status
Not open for further replies.

jajinder

Technical User
Mar 11, 2004
88
NL
Hi,

Got me a Combo1_Click() event. When I press the down-arrow the code executes. Is it possible to do that also with the "Enter-Key"?

I thought that it would be possible to write the code under a KeyPress Event, but then nothing happened.

---------------------------------------
This will be the day when all of God’s children will be able to sing with a new meaning, “My country, ‘tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the pilgrim’s pride, from every mountainside, let freedom ring. - Marten Luther King
 
Tried this on mine and it works

Private Sub Combo1_Click()
Beep
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
Beep
End Sub

David Lerwill
"If at first you don't succeed go to the pub"
 
I understand that you will here a beep, but my code did not execute...
This is the code I already have in the KeyPress()
Code:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case 8, 65 To 90            
    Case 8, 97 To 122           
    Case Else
        KeyAscii = 0
    End Select
End Sub
Now I want this code to be executed when I press the "Enter-Key"
Code:
Set rs = New Recordset
rs.Open "SELECT * FROM POSTCODE WHERE PLAATS = '" & Combo1.Text & "'", cn, adOpenDynamic

    If Not rs.EOF And Not rs.BOF Then Text1.Text = rs.Fields("GEMEENTE").Value
    If Not rs.EOF And Not rs.BOF Then Text2.Text = rs.Fields("PLAATS").Value
    rs.Close
    Set rs = Nothing
End Sub

---------------------------------------
This will be the day when all of God’s children will be able to sing with a new meaning, “My country, ‘tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the pilgrim’s pride, from every mountainside, let freedom ring. - Marten Luther King
 
something like

Private Sub Combo1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 13
GoTo Enter_Pressed
Case Else
KeyAscii = 0
End Select

Exit Sub
Enter_Pressed:

Set rs = New Recordset
rs.Open "SELECT * FROM POSTCODE WHERE PLAATS = '" & Combo1.Text & "'", cn, adOpenDynamic

If Not rs.EOF And Not rs.BOF Then Text1.Text = rs.Fields("GEMEENTE").Value
If Not rs.EOF And Not rs.BOF Then Text2.Text = rs.Fields("PLAATS").Value
rs.Close
Set rs = Nothing
End Sub


David Lerwill
"If at first you don't succeed go to the pub"
 
That it would be so simple.... I´d never knew... Have a shiny my friend and many thanx for the solution... ;)

---------------------------------------
This will be the day when all of God’s children will be able to sing with a new meaning, “My country, ‘tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the pilgrim’s pride, from every mountainside, let freedom ring. - Marten Luther King
 
jajinder,

In KeyPress event, you set KeyAscii to 0 when it was 13 (the Enter) rendering it to the state like the Enter was not hit at all. dwlerwill gave you correct idea of how to handle this (although "goto" I would not use: this is considered to be the not best practice). I am not sure if you need to set almost all KeyAscii codes to 0. Try not to set them to see if this satisfies you.

vladk
 
I agree, do not use goto, here's an extreme example of why it's bad thread222-839882. Just move the Enter_Pressed stuff under the Case 13.


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
I do agree that goto is not the best method I only use it occasionally use it myself

David Lerwill
"If at first you don't succeed go to the pub"
 
Private Sub Combo1_KeyPress(KeyAscii As Integer)
call combo1_Click
End Sub
 
Thank you all once more for your support ;) It work fine now. Never knew that I could call a "Private Sub" within the same form. Learned something again. You also have a star pkailas.



---------------------------------------
This will be the day when all of God’s children will be able to sing with a new meaning, “My country, ‘tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the pilgrim’s pride, from every mountainside, let freedom ring. - Marten Luther King
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top