Results 1 to 8 of 8
  1. #1
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Capturing F1 key so I can display Help screen

    Currently in my MS Access 2010 application if I press the F1 key I get the Microsoft Help. I want to capture that keypress and display my own Help screen (PDF document ). I would appreciate any help with this problem as I don't want to have to place a command button on every form etc in order to display Help screen(s). I want to capture the FI key then read the "Tag" property of the form or control pressed and use the Tag to display the proper Help file which is saved in a table by "Tag" values.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    in form design set KEYPREVIEW = TRUE

    then in the code for the form_KEYDOWN event , capture the F1 key, then run your help.
    The getHelp() is your own version of help

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF1 Then getHelp()

  3. #3
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    After doing a little Google-fu, it appears that this isn't an uncommon issue. There used to be a way of making custom help files that could then be integrated with Access, but after Microsoft locked Access from running these from a network drive, they fell out of favor.

    The consensus now seems to be that you should use an AutoKeys Macro to start up your own custom help system. I've never used one before, but it looks like an AutoKeys Macro is simply a macro that is run by a keyboard shortcut (in your case, pressing F1) instead of a Form Event.

    Setting up an AutoKeys Macro: https://support.office.com/en-sg/art...b-a3c81af676be

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would not use "SendKeys"; I have read too many sites that say do not use SendKeys.

    This is the code I use to capture F-keys:
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case vbKeyF1
                KeyCode = 0
                '   More code here
            Case vbKeyF12
                KeyCode = 0
                '     Different code here
        End Select
    
    End Sub
    The line "KeyCode = 0" clears the keypress code so nothing else gets the keycode.

    Note that this is in Form_keydown event property.
    And, as ranman256 said, be sure in form design to set KEYPREVIEW = TRUE.

  5. #5
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Sending F1 key

    Quote Originally Posted by ssanfu View Post
    I would not use "SendKeys"; I have read too many sites that say do not use SendKeys.

    This is the code I use to capture F-keys:
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case vbKeyF1
                KeyCode = 0
                '   More code here
            Case vbKeyF12
                KeyCode = 0
                '     Different code here
        End Select
    
    End Sub
    The line "KeyCode = 0" clears the keypress code so nothing else gets the keycode.

    Note that this is in Form_keydown event property.
    And, as ranman256 said, be sure in form design to set KEYPREVIEW = TRUE.
    Thanks for the quick reply. I see how the code works but is there any way to run an application level "trap" for the F1 key so I don't have to write this code for every form or control Iwhere I need to display my Help process?

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    but is there any way to run an application level "trap" for the F1 key
    The code I posted is a FORM level event. I don't know of an application level event.

    write this code for every form or control
    I have not tried (actually, I have not needed) a control level keydown event.


    You could try putting code in a standard module and calling it from the Form KeyDown event.
    But you must have code for the Form KeyDown event in every form.
    Something like this (air code):
    (each form)
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Call OpenHelp(KeyCode, Shift, Me.Name)
        KeyCode = 0
    End Sub
    (standard module)
    Code:
    Sub OpenHelp(pKeyCode As Integer, pShift As Integer, pFormName As String)
        Select Case pKeyCode
            Case vbKeyF1
                Select Case pFormName
                    Case "Form3"
                        MsgBox "You pressed F1 in form:  " & pFormName
                    Case "Form2"
                        ' Open different form help here
                End Select  'pFormName
            Case Else
        End Select    'KeyCode
    End Sub
    You could also leave out the code to select which form the help is for for and just use one help screen (PDF document).
    =============================
    Warning: I corrupted the VBA project one time by copying a subroutine in a report and pasting it in 5 other reports without compiling the IDE or dB.
    It took me two weeks to recover the FE.

    What I do now to copy code into multiple forms/reports:
    Copy the code and paste it into a text file.

    Begin loop
    ...Open the form/report, click on the event (in this case it will be the form KeyDown event) and paste only the lines between "Sub" and "End Sub".
    ...Compile the code in the IDE (Debug-compile).
    ...Save the form/report.
    ..."Compile and Repair" from the menu (the whole dB).
    loop until done

  7. #7
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Thanks for help on F1 key capture

    Quote Originally Posted by ssanfu View Post
    The code I posted is a FORM level event. I don't know of an application level event.


    I have not tried (actually, I have not needed) a control level keydown event.


    You could try putting code in a standard module and calling it from the Form KeyDown event.
    But you must have code for the Form KeyDown event in every form.
    Something like this (air code):
    (each form)
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Call OpenHelp(KeyCode, Shift, Me.Name)
        KeyCode = 0
    End Sub
    (standard module)


    Code:
    Sub OpenHelp(pKeyCode As Integer, pShift As Integer, pFormName As String)
        Select Case pKeyCode
            Case vbKeyF1
                Select Case pFormName
                    Case "Form3"
                        MsgBox "You pressed F1 in form:  " & pFormName
                    Case "Form2"
                        ' Open different form help here
                End Select  'pFormName
            Case Else
        End Select    'KeyCode
    End Sub
    You could also leave out the code to select which form the help is for for and just use one help screen (PDF document).
    =============================
    Warning: I corrupted the VBA project one time by copying a subroutine in a report and pasting it in 5 other reports without compiling the IDE or dB.
    It took me two weeks to recover the FE.

    What I do now to copy code into multiple forms/reports:
    Copy the code and paste it into a text file.

    Begin loop
    ...Open the form/report, click on the event (in this case it will be the form KeyDown event) and paste only the lines between "Sub" and "End Sub".
    ...Compile the code in the IDE (Debug-compile).
    ...Save the form/report.
    ..."Compile and Repair" from the menu (the whole dB).
    loop until done
    Thanks for the arning but it came too late. Wow, what a mess. I had to load the application through the command line with the command /Decompile and then recopy etc. Thanks for the Help and wish me luck.

  8. #8
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124
    TDailog Help form for MS and I can't seem to get rid of it. So +{F1} works.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-24-2015, 05:29 PM
  2. Project Explorer display on top of screen
    By dmgg in forum Programming
    Replies: 3
    Last Post: 02-03-2014, 06:05 PM
  3. Replies: 3
    Last Post: 11-12-2013, 02:57 PM
  4. Replies: 3
    Last Post: 02-22-2012, 06:05 PM
  5. Replies: 11
    Last Post: 06-05-2011, 09:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums