Prevent form from moving from a record

FuzMic

DataBase Tinker
Local time
Tomorrow, 05:55
Joined
Sep 13, 2006
Messages
744
Hi forum mates

How can we prevent a single form from moving from a record until some command button is pressed. The setting of me.navigationbutton = false will not stop a pageUp, pageDown, Home and End KeyPress. Help much appreciated.
 
You might be able to trap these key actions with the OnKeyDown event.
 
Thanks John

I will give it a try in that direction.

By the way cycle to just current record don;t work
 
That's correct I think the only way is to trap those key actions that will take you from your current record and cancel their action.
 
I was thinking about keypress event but have no idea how to trap the keycodes earlier.

On keydown event, I understand the related key codes are 0x21 to 0x24; I presume on the keydown event if the keycodes match these, then cancel the event. By the way is 0x21 number or txt?
 
To disable the PAGE UP and PAGE DOWN keys in a form, follow these steps:

Open any database, open any form in Design view, and set the form's properties as follows:

Code:
      KeyPreview: Yes
      OnKeyDown: [Event Procedure]

Click the Build button to the right of the OnKeyDown property and type the following procedure:

Code:
      Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
         Select Case KeyCode
            Case 33, 34
               KeyCode = 0
         End Select
      End Sub


NOTE: KeyCodes 33 (&H21) and 34 (&H34) represent PAGE UP and PAGE DOWN, respectively. You can disable other keys on the form by including the appropriate KeyCode in the Case statement. For example, if you also want to disable the ESC key on the form, add KeyCode 27 to the Case statement as follows:

Code:
      Case 27, 33, 34

Open the form in Form view and notice that the PAGE UP and PAGE DOWN keys have no effect.
 
Thanks DCrake

Just before i read your response, following is what i wanted to write

On tinkering with Keydown event (keypreview = on), i did find the 4 record changing keycodes, namely 33-36.
The bad news is docmd.cancelevent won't cancel these keys after trapping it in the event. I don't know of another way out unless someone help.

The cycle = 0-2 however do prevent moving away from the current record on pressing cursor keys; thread question remains.


Then you came along, the punch line i believe is
KeyCode = 0

I will check it out. Thanks for the effort, mate. :)

FINAL COMMENT: CDrake your advice checks out fine, its done. Thanks
 
Last edited:

Users who are viewing this thread

Back
Top Bottom