Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Key Strokes and Functions (Access 2k sr1)

    Is it possible to attach a sub or function to a set of Key Strokes (Ctrl d for example)? I have a sub that inserts today's date into controls on double-clicking and I thought it would be useful to be able to use key combinations too.
    Peter

  2. #2
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Key Strokes and Functions (Access 2k sr1)

    What's wrong with using Ctrl + ; to insert today's date? <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

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

    Re: Key Strokes and Functions (Access 2k sr1)

    FYI, there is already a short-cut keystroke that inserts the current date - CTRL + ;
    It is also possible to assign new short-cut keystrokes with the AutoKeys macro, but you may well be wiping out standard short-cuts that people expect to work based on experience in other databases.
    Wendell

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Key Strokes and Functions (Access 2k sr1)

    Steve and Wendell
    Thanks for the quick reponse. I know quite a few kb shortcuts but not that one (how embarrassing). Still that was a minor part of the question. I've tried various actions to work a kb shortcut using Keyup, keydown etc but I can't seem to get it absolutely right. I've been able to get it from one key but not a combination which of course is what's required.
    Peter

  5. #5
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Key Strokes and Functions (Access 2k sr1)

    Peter,

    Here is how I would capture a Ctrl+D in a textbox.

    <pre>Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)

    Dim CtrlDown As Boolean

    'Determine if the Ctrl key was pressed
    CtrlDown = (Shift And acCtrlMask) > 0

    'Check to see if CTRL+D was pressed
    If CtrlDown = True And KeyCode = vbKeyD Then
    'Insert the current Date into the textbox
    Text0.Text = Date
    End If

    End Sub</pre>


    This is the KeyDown event of the particular textbox.

    You can also capture this at the form level, by placing the text into the KeyDown event of the form AND setting the Key Preview setting to Yes.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

Posting Permissions

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