设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 3184|回复: 6
打印 上一主题 下一主题

How to control Tabbing and "Enter" key movement in and out of a s

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2005-8-15 19:04:00 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
标题:How to control Tabbing and "Enter" key movement in and out of a sub-Form and a Main Form.

原作者:ATTAC Consulting Group



When a user presses the tab key or the enter key when they are in the last field on a main form, where the next field is a sub form, this will automatically result in the cursor moving to the first control in the subform. However, if the user then holds down the Shift key and presses the tab key, (to move backward in the form,) rather than re-entering the main form, the cursor will either move to the last field on the sub form (if on the first record of the sub form,) or to the previous record in the sub form. Similarly, if the user is on the last control in the sub form and presses the enter key, they will be taken to the next record in the sub form, rather than to next control in the main form. This behavior can be modified to progress directly between the main form and current record of the sub form by using event procedures in the "On Key Down" event of the sub-Form's first and last controls. To do this use the code below. (Note the "arent" property of the sub form refers to the main form):

1. On the Declarations page of the Form's module enter the following lines: Const Key_Tab = &H9

Const Key_Return = &HD

Const SHIFT_MASK = 1

2. In the "On Key Down" event of the first control on the sub-form create an event procedure and enter the following code: ShiftDown = (Shift And SHIFT_MASK) > 0



   If KeyCode = Key_Tab Then

        If ShiftDown Then

            Me.Parent!SomeControl.SetFocus  

            KeyCode=0

       End If

   End If



3. In the "On Key Down" event of the last control on the sub-form create an event procedure and enter the following code:   ShiftDown = (Shift And SHIFT_MASK) > 0



    If KeyCode = Key_Tab Then

        If ShiftDown = 0 Then

            KeyCode = 0

            Me.Parent!SomeControl.SetFocus

        End if

    ElseIf KeyCode = Key_Return Then

           KeyCode = 0

           Me.Parent!SomeControl.SetFocus

    Else Exit Sub

    End If



To stop the user from re-entering the main form, without moving to the next record, simply remove the lines of code which set the focus on a control of the Main Form.

Access 95 and 97: If you need to trap key actions and movement in Access 95 and 97, especially if it involves multiple controls and/or sub-forms (e.g. sub-forms on a tab control,) you can save time and coding by creating a single function for the form by setting the Key Preview property of the form to "Yes", and writing a single function in the OnKeyDown event of the form. You can use a select case routine to test the CurrentControl.name and set your form movement from there.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-19 18:33 , Processed in 0.073236 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表