Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check boxes and code (Access 2000)

    Hi Everyone,

    I don't know if I am looking for the difficult answer, however I was wondering, if I have a checkbox on a form and instead of click it with the
    mouse I want to be able to tab through the form and press enter to select do I need to place some sort of code in the

    Private Sub Children_under_21__Enter()

    End Sub

    Children under 21 is the name of my field.

    Thanks Kindly,

    Kerrie [img]/forums/images/smilies/smile.gif[/img]

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Check boxes and code (Access 2000)

    Not sure if I have question right, but if you are tabbing thru form, when you get to checkbox you can use spacebar to check/uncheck the checkbox without having to use mouse.

    HTH

  3. #3
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check boxes and code (Access 2000)

    Hi MarkD,

    Is there a way you can use the enter key instead of the spacebar?

    Thanks

    Kerrie [img]/forums/images/smilies/smile.gif[/img]

  4. #4
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Check boxes and code (Access 2000)

    Hi,

    Be advised, I am NOT expert on Keyboard events - I try to avoid their use whenever possible (too many things can go haywire....). As experiment I was able to toggle checkbox with Enter key using following technique:

    First declare module-level variable in form module Declarations:
    <pre>Dim intOptionSetting As Integer</pre>

    Then add following On Enter and On Exit event procedures for your checkbox:
    <pre>Private Sub Children_under_21_Enter()

    Dim strOptionName As String
    strOptionName = "Move After Enter"
    intOptionSetting = Application.GetOption(strOptionName)

    'Move After Enter settings:
    '0 = Don't Move
    '1 = Next field
    '2 = Next Record

    If intOptionSetting <> 0 Then
    Application.SetOption strOptionName, 0
    End If

    End Sub
    </pre>

    <pre>Private Sub Children_under_21_Exit(Cancel As Integer)

    'Reset Keyboard option:
    Dim strOptionName As String
    strOptionName = "Move After Enter"
    Application.SetOption strOptionName, intOptionSetting

    End Sub</pre>

    To toggle checkbox use KeyPress event:
    <pre>Private Sub Children_under_21_KeyPress(KeyAscii As Integer)

    If KeyAscii = 13 Then
    If Me.Children_under_21 = True Then
    Me.Children_under_21 = False
    Else
    Me.Children_under_21 = True
    End If
    Else
    'nothing
    End If

    End Sub</pre>

    The reason for the On Enter & On Exit procedures is that the Keyboard Options (Tools>Options) will impact KeyPress event for Enter key. If option not set to "Don't Move" (value = 0) then Enter will move focus to either next field or next record and KeyPress event will not be triggered. Sample code uses Application GetOption and SetOption methods to retrieve current setting upon entering checkbox (and setting to 0 if necessary) and to reset to previous setting upon exiting checkbox field. You can test this by setting keyboard options for Enter to "Next field" and use Enter to navigate thru form. When you get to checkbox Enter will toggle value rather than moving to next field. You can then tab to exit checkbox.

    As noted I am not expert in Keyboard events. Maybe someone who is more knowledgeable in this area will have simpler solution.

    HTH

    PS: Wouldn't just using spacebar be simpler??

  5. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Check boxes and code (Access 2000)

    In addition to MarkD's comments, you should be aware that the Enter key and the Tab key have some assumed meanings in the Access user interface. In general they both act as a trigger to move to the next field. Changing that behavior can lead to disasterous results if you have even a small bug in your logic. Having been down this path a couple of times and gotten into all sorts of trouble, we now tell clients that they just have to train the data entry staff in how to use Access forms! <img src=/S/scold.gif border=0 alt=scold width=50 height=15>
    Wendell

  6. #6
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check boxes and code (Access 2000)

    Hi Mark,

    Thank you

    Kerrie [img]/forums/images/smilies/smile.gif[/img]

  7. #7
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check boxes and code (Access 2000)

    Hi WendellB,

    I tried and you are right, it creates lots of trouble.

    Thanks for the advice.

    Kerrie [img]/forums/images/smilies/smile.gif[/img]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •