Selecting menu numbers with return key

Gazza2

Registered User.
Local time
Today, 05:19
Joined
Nov 25, 2004
Messages
184
I have a form menu as a startup page and i would like my users to select a number and press the enter key to open up a new form and close the menu.
The menu numbers and descriptions are done with labels, the users have a text box at the bottom were they will type in the number of the new form that they want to edit then they will press enter and it will take them to the new form and close the menu.

Any help will be appreciated
 
Last edited:
one way of doing this is to use the OnKeyDown event of your form and do a search on this forum for the word KeyCode.
 
Do you really want them to type a number in a textbox? The normal method is to click on a button associated with the form/report to be opened. In the first case, you would use the AfterUpdate event of the textbox. In the second case, you would use the click event of a button. In both cases, you would use the OpenForm Method to open a form or the OpenReport method to open a report. Look them up in help.
 
Code I used

Thanks for the advice both of you but I entered the following code into both the onkeydown event and the afterupdate event for the text box one at a time and made sure that keyprieview for the form is set to yes but still couldnt get it to work.

private sub Text1_afterupdate()
select case keycode
case vbKey1 + vbKeyreturn
keycode = 0
docmd.openform"form1",acnormal
docmd.close"menu"
end select

end sub

this is only an example to select the first menu item and all that happens is that the number disappears.
 
The key code is irrelevant for this purpose. All you are interested in is what they typed in the text box.
Code:
private sub Text1_afterupdate()
    Select Case Me.Text1
        Case 1    
            doCmd.OpenForm "form1"
        Case 2    
            doCmd.OpenForm "form2"
        Case 3
            doCmd.OpenForm "form3"
        Case Else    
            MsgBox "Invalid Selection.  Please try again", vbOKOnly
    End Select
    doCmd.Close "menu"
End Sub
 
I entered the code as you have written it and changed the names of the forms to the names of miine but it is still not working.

But i have just noticed that the number does not actually disappear it moves up a line so if i press the delete key the number reappears.

thanks for your help so far.
 
Is the "Enter Key Behaviour" property of the text box in question set to "Default", or "New Line In Field" ?
 
is the code similar for using letters to open a new form or is it completely different.

The reason being that in some forms that display data the users may have to open another form from within that form and they want to use the first letters of the form name that they want to open.
 
No, the code is the same except that string values are contained within quotes.

Case "A"
Case "B"
etc.
 

Users who are viewing this thread

Back
Top Bottom