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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Key Presses My Button - How?

Status
Not open for further replies.

Maillme

Technical User
Mar 11, 2003
186
NL
Hi there,

I have a search form, with 3 fields....i would like it so that if my user enters anything into these three fields, and hits enter - it will "click" my search button on the form.

How is this acheived?

many thanks again for all your help,

Neil
 
and hits enter
Make your search button the default one.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Command buttons have a property called "DEFAULT" set it to "Yes". will do the trick.

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
Thats great - BUT, my form has a tab control, with 2 different search options, and...............well.............2 different search buttons :( - so this default only works for one of these...........any ideas how i can make sure this works for both my search buttons?

thanks,

Neil
 
How about setting the focus to the appropriate command button in the After Update Event of the textbox and using the On Got Focus event to run the search? This way, any method of exiting an updated textbox will cause the search to run. [ponder]
 
I dont think that would really work (if my understanding is correct - which it may not be!), as the 3 txt boxes are for different data:

first Name
Surname
location

But it could be any one of these that is used, or even a combination of both......

So, the user could enter "Cath" in first name field, but the above method wouldnt work unless they were moving onto the nxt field - i woudl like it so if they pressed tner it woudl run the search.

thanks,

Neil
 
Why 2 search buttons ?
Can't you merge the two Click event procedures into one ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How about something like this?
Code:
Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        'Do something here
        MsgBox "enter button"
    End If
End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
I'm sure i possibly could merge the 2, but it took me the best part of yesterday, and alot of help from coleagues and this site to get this one working! :(

It searches 2 different tables, using different criteria.......

Neil
 
is ther not a way to do this on the "keypress event" of the txt box's? Or would this effect the other button, on the other tab......

many thanks,

Neil
 
So next time ask more precisely.
You clearly asked for ONE button.
 
No.. as far as I know..
KeyPress recognize KeyAscii code. You will not get many of the keys recognized by the KeyPress Event.
see
Code:
Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
    MsgBox KeyCode
End Sub

Private Sub Text0_KeyPress(KeyAscii As Integer)
   MsgBox KeyAscii
End Sub
You can call any command from the event. I have wriiten "Do Something here" in the first sample. sample below
[tt]
Call Command1_Click
[/tt]

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
Now I will ask why button at all?
delete the command buttons , keep the code there and call the respective code from the KeyDown event.

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
oh....i am totally confused now :(

OK, sorry for me rambling on, im just a bit confused now - but ZmrAbdulla, i think i know what you are meaning.

I have a form, with 2 tabs on it (i can email you a screen grab if it would help).


Each tab has it's own search function, and button - i would like to be able to add code, so that depending on what tab you are on, and when you press enter, i would like it to do the same, as if you had clicked the search button on that tab.

I think taking the button away all together seems like a good idea, but only if i was the one using the database, but i'm not - and i suspect this could confuse a few people (who dont know to hit the enter button).

thank you very much for everyone's help,

Neil
 
OK simple logic place 2 textboxes and 2 command buttons on the form
name them like below and try the code
Textbox 1=Text1
Textbox 2=Text1
Command Button1 =cmdSearch1
Command Button2 =cmdSearch2

Code:
Private Sub cmdSearch1_Click()
    MsgBox "You pressed Command Search 1"
End Sub
[COLOR=green]'=============================================[/color]
Private Sub cmdSearch2_Click()
    MsgBox "You pressed Command Search 2"
End Sub
[COLOR=green]'=============================================[/color]
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        Call cmdSearch1_Click
    End If
End Sub
[COLOR=green]'=============================================[/color]
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        Call cmdSearch2_Click
    End If
End Sub

Remember!! Buttons on the tabcontrol is not the collection of tabcontrol but of form.

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
Here is another solution with one command button, one tabcontrol, and 2 text boxes. Textboxes are on each page of the tabcontrol.

Code:
Private Sub Command1_Click()
    Select Case Me.TabCtl0.Value
    Case 0
        MsgBox "You are at page1"
    Case 1
        MsgBox "You are at page2"
    End Select
End Sub
[COLOR=green]'================================[/color]
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
[b]'DO SOMETHING HERE[/b]
        Call Command1_Click
    End If
End Sub
[COLOR=green]'================================[/color]
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
[b]'DO SOMETHING HERE[/b]
        Call Command1_Click
    End If
End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
got it working - thank you very much for all your help,

Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top