Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change from keydown to conditional Autokeys to open Word Document? 1

Status
Not open for further replies.

SiberBob

Programmer
Aug 28, 2002
107
0
0
US
Can someone give me an example of using Autokeys to capture a function key and have that function key open a Word document?

I have found a number of references to opening word from access, and references to autokeys, but never any of the two combined.

I have the following code in my application
Code:
    If KeyCode = vbKeyF1 Then Application.FollowHyperlink "Y:\Databases\Instructions.doc", , True

Which opens a specific document, then opens the MS Access help application.

I want to stop the MS Access help file from opening. I am guessing that the [blue]Application.FollowHyperlink[/blue] is not capturing the F1, but just being activated by it.

I have tried to use AutoKeys to RunCode and point to a
Code:
Public Sub ShowCustomHelp()
...
End Sub
But that doesn't work. The Autokeys won't find the fuction.

I have put the Sub ShowCustomHelp() in it's own module, and made sure MS word 9.0 was checked in References.

I can't figure out how to get the F1 to open a word document from Autokeys. Any input would be appreciated.



 
When using the keydown event, try canceling the keystroke within the event:
[tt]KeyCode=0[/tt]

- but be aware, if the user hits F1 anywhere where the keystroke isn't captured (reports), the same occurs

Don't know much about the autokeys, but the helpfile states the function keys can be trapped with the syntax:

[tt]{F1}[/tt]

Then you'd need to try to run/call a public function not a sub (after selecting the RunCode action)

Roy-Vidar
 

Ok,

I am closer now. I don't know what I had messed up but this is what I have now:

Code:
Function ShowCustomHelp()
        
    Select Case Screen.ActiveForm.Name
        Case "Dealer Apps"
            fHandleFile "Y:\Databases\DealerAppInstructions.doc", WIN_MAX
        Case "Rolodex"
            fHandleFile "Y:\Databases\RolodexInstructions.doc", WIN_MAX
        Case Else
            Exit Function
    End Select
    
End Function

I am using the [blue]AutoKeys[/blue] macro to capture [blue]{F1}[/blue] and [blue]RunCode / ShowCustomHelp()[/blue].

This opens my Word Document as desired, but after I close my Word Document or switch back to my Access app I get the following error:
Run-time error '2475':

You entered an expression that requires a form to be the active window.

Then I get the Macro failure box titled Action failed and indicating the following:
MacroName: AutoKeys:{f1}
Condition: True
Action Name: RunCode
Arguments: ShowCustomHelp()

Clicking "Debug" on the error message highlights the Select Case line of my function code. Any thoughts?

 
Sorry, don't know, I don't use macros, and seldom/never use the screen.activeform thingie neither, the latter one because it has problems when operations switches focus.

Just guessing by the message, perhaps one of the following?
* the call is performed twice, the second time there's no active form
* when returning from Word, there's no active form

Two suggestions:

[tt]Function ShowCustomHelp()
dim strFName as string
Select Case Screen.ActiveForm.Name
Case "Dealer Apps"
strFName= "Y:\Databases\DealerAppInstructions.doc"
Case "Rolodex"
strFName = "Y:\Databases\RolodexInstructions.doc"
Case Else
Exit Function
End Select
fHandleFile strFName, WIN_MAX
End Function[/tt]

Don't know it that's of any help...

Or try dumping the name of the current form into a public variable when opening the form, then there wouldn't be any need to use screen.activeform.

Roy-Vidar
 

Your idea worked wonderful! I dump the name of the form into a global variable when I open the form. Then I use that variable to test for which form is open. Here is the working code:

Code:
Function ShowCustomHelp()
    Dim strFName As String
    Select Case GlobalVariables.CurrentFormName
        Case "Dealer Apps"
            strFName = "Y:\Databases\DealerAppInstructions.doc"
        Case "Rolodex"
            strFName = "Y:\Databases\RolodexInstructions.doc"
        Case Else
            Exit Function
    End Select
    fHandleFile strFName, WIN_MAX
End Function

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top