Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Mar 2004
    Posts
    185
    Thanks
    37
    Thanked 1 Time in 1 Post
    I have an application which uses VBA for Access 2007. It has a form with the "Help File" property pointing to a properly formulated hlp file - .chm. However with the form window active, F1 just pulls up the standard (useless) Access help window instead of my application dedicated help file. I can invoke my help file with a button, but would like F1 to do this. How can I achieve this please?

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Peter,

    Add the following code {with appropriate adjustments} to your form:

    Code:
    Private Sub Check0_KeyDown(KeyCode As Integer, Shift As Integer)
    
       MsgBox "The code for the key pressed is: " & Format(KeyCode), vbOKOnly
       
       If KeyCode = 112 Then
          KeyCode = 0   '*** Resets the code so the Access file isn't called ***
         'call your help file here'
       End If
       
    End Sub
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    My recollection (and I have just tested this) is that the KeyDown event for a form only fires if the KeyPreview property of the form is set to Yes.

    The other approach to this is to create an Autokeys macro but this would reassign F1 throughout the whole database, not just a specific form.
    Regards
    John



  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quote Originally Posted by John Hutchison View Post
    My recollection (and I have just tested this) is that the KeyDown event for a form only fires if the KeyPreview property of the form is set to Yes.
    John, I checked my test form and the KeyPreview property was set to NO and it still worked. This is Access 2003 SP-3.
    Attached Images Attached Images
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    But you have attached the code to a specific control on the form, not to the form itself.
    Regards
    John



  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quote Originally Posted by John Hutchison View Post
    But you have attached the code to a specific control on the form, not to the form itself.
    Ah! Right you are John. Thanks for setting me straight.

    The code should have been:
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    
    '*** Must set the Key Preview property to Yes for this to work. ***
    
       MsgBox "The code for the key pressed is: " & Format(KeyCode), vbOKOnly
       
       If KeyCode = 112 Then
          KeyCode = 0   '*** Resets the code so the Access file isn't called ***
         'call your help file here'
       End If
    
    End Sub
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  7. #7
    2 Star Lounger
    Join Date
    Mar 2004
    Posts
    185
    Thanks
    37
    Thanked 1 Time in 1 Post
    What a team - thanks guys

Posting Permissions

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