Re: Open form with Enter key???

From: Niklas Östergren (niklas.ostergren_at_spray.se)
Date: 04/28/04


Date: Wed, 28 Apr 2004 13:30:31 +0200

Hi Niel!

Thank´s a lot! It works now! The problem I hade is that I was running the
code from the KeyPress_Event BUT hade the Locked propertie set for the
control.

Is there any way around this because I realy would like to have the
propertie Locked = True on all the controls accept for one. The form is only
a list of records and I don´t want the user to be able to edit the records
from this form (frmListMembers). If the user need to edit the records he/she
just needs to open up (frmPerson) which I want to open with help of Return
key!

TIA!
// Niklas

"Neil" <neil@_NoSPAM_haywood2k3.freeserve_NoJUNK_.co.uk> skrev i meddelandet
news:c6nvu6$7bv$1@titan.btinternet.com...
> Niklas,
>
> Every Access control (as far as i know) has a KeyPress event. The forms
> actually have a KeyPreview property which will in turn send the keypress
to
> the KeyPress of a form no matter what control has the focus at the time of
> the user pressing enter. For example:
>
> You have a form named frmTest. This has a textbox on it named txtMyTextBox
> and a ComboBox named cboMyCombo. If you had programed the KeyPress event
for
> the textbox only then the code would look like:
>
> Private Sub txtMyTextBox_KeyPress(KeyAscii As Integer)
>
> If vbKeyReturn Then
> docmd.OpenForm "frmPerson",,,"[PersonID]=" & intPersonID
> end if
>
> End Sub
>
> The code above would run evertime the user pressed *any* key in the
textbox.
> Your code checks and only acts if the Return key has been pressed. If you
> put the same procedure in the forms KeyPress event (KeyPreview has to be
set
> to yes for this to work as the form doesnt receive the focus unless there
> are no controls on it - not much use then :-)).
>
> Private Sub Form_KeyPress(KeyAscii As Integer)
>
> If vbKeyReturn Then
> docmd.OpenForm "frmPerson",,,"[PersonID]=" & intPersonID
> end if
>
> End Sub
>
> The code above would run evertime any key was pressed in any control on
the
> form. Again, the form would only open if it was the Return key that had
been
> pressed.
>
> Hopefully, using the above information, you can now work out where you
need
> to place the code and in which controls (if any) to get the desired effect
> you are after.
>
> HTH,
>
> Neil.
>
> "Niklas Östergren" <niklas.ostergren@spray.se> wrote in message
> news:O90AyfOLEHA.3300@TK2MSFTNGP10.phx.gbl...
> > Hmm!
> >
> > I havn´t tryed it out but I was to curious to wait untill late evening!
> > I don´t know if I have missunderstod your reply but the DoCmd.OpenForm
> > works. What I don´t get is how to fire the code when <Enter / Return>
key
> is
> > pressed. That´s my Q!
> >
> > TIA
> > // Niklas
> >
> >
> > "Albert D. Kallal" <kallal@msn.com> skrev i meddelandet
> > news:egSybJOLEHA.2736@TK2MSFTNGP11.phx.gbl...
> > > I guess it depends on where your current cursor is..or what is
currently
> > > displayed on the screen.
> > >
> > > But yes..it is a great idea to enable the Enter key to open up a form
> > based
> > > on the current details.
> > >
> > > If you look at he following screen shots....I always enable the cursor
> > when
> > > the user hits enter.
> > >
> > > http://www.attcanada.net/~kallal.msn/Articles/Grid.htm
> > >
> > > The code use is:
> > >
> > > Private Sub MNr_KeyPress(KeyAscii As Integer)
> > > If vbKeyReturn Then
> > > docmd.OpenForm "frmPerson",,,"[PersonID]=" & intPersonID
> > > end if
> > > End Sub
> > >
> > > of course, the above assumes a key id of personID. Often, the key id
is
> > > "id"..so you would use:
> > >
> > > docmd.OpenForm "frmPerson",,,"id = " & me.ID
> > >
> > > Here is some screen shots where I use the above idea..and again enter
> key
> > > opens up the form...
> > >
> > > http://www.attcanada.net/~kallal.msn/Search/index.html
> > >
> > > --
> > > Albert D. Kallal (MVP)
> > > Edmonton, Alberta Canada
> > > pleasenonoSpamKallal@msn.com
> > > http://www.attcanada.net/~kallal.msn
> > >
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Multiple Control Event Classes
    ... I have set up a form with sixty textbox controls on it to allow the user ... AfterUpdate event procedures for each control, ... one event for each control, i.e. AfterUpdate, KeyPress and Enter. ... Private Sub TBDGroup_AfterUpdate ...
    (microsoft.public.excel.programming)
  • Re: Setfocus - Error 2108
    ... Well how do I clear the events for the control. ... Private Sub cboCust_ID_BeforeUpdate ... > - the KeyDown, KeyPress, KeyUp, Change, BeforeUpdate, AfterUpdate, ... > - the KeyDown, KeyPress, KeyUp, and Error events of ...
    (microsoft.public.access.forms)
  • Re: Simple KeyPress Help
    ... this means that the form handles the keypress before other objects. ... Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) ... If you want control over which control gets what key. ...
    (comp.lang.basic.visual.misc)
  • Re: restricting key presses
    ... > I have tried the following in the keypress event: ... Dim LastPosition As Long ... Static SecondTime As Boolean ... Private Sub Text1_MouseDown(Button As Integer, ...
    (microsoft.public.vb.controls)
  • Re: KeyDown, KeyPress, KeyUp Problem
    ... Wie kommst du denn nun an den Event dran, ... KeyPress schon auch an das eigene Control gesendet ... ich nie selbst den KeyPress event. ... kann und möchte ich kein embedded control haben und dennoch KeyPress Event ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)