PC Review


Reply
 
 
Greg B
Guest
Posts: n/a
 
      30th Jul 2008
I asked last week about access keys and I need to ask a bit more.

> Sub SetupF2()
> Application.OnKey "{F2}", "OpenForm"
> End Sub
>
> Sub OpenForm()
> UserForm1.Show
> End Sub


This was the code I was given but it does not seem to work with userform. I
placed the code in the userform activate macro, and when I press f2 it does
not do a thing.

Is it possible to use the function keys from a userform?

Thanks
Greg

 
Reply With Quote
 
 
 
 
Greg B
Guest
Posts: n/a
 
      30th Jul 2008
Same problem I cant trigger it from the userform. I start the program and
it loads the MAIN userform. It is on this userform I want to have the
ability to use short cut keys.

Sorry I wasnt clear.

Greg

"Office_Novice" <(E-Mail Removed)> wrote in message
news:674F5CE5-2CB3-4A95-8CE0-(E-Mail Removed)...
> Put This in The 'ThisWorkbook Module:
>
> Sub SetupF2()
> Application.OnKey "^{F2}", "OpenForm" 'I added the Ctrl key so Ctrl +F2
> End Sub
>
> in a standard module put:
>
> Function OpenForm()
> UserForm1.Show
> End Function
>
> HTH
>
> "Greg B" <browgregory"nospam" wrote:
>
>> I asked last week about access keys and I need to ask a bit more.
>>
>> > Sub SetupF2()
>> > Application.OnKey "{F2}", "OpenForm"
>> > End Sub
>> >
>> > Sub OpenForm()
>> > UserForm1.Show
>> > End Sub

>>
>> This was the code I was given but it does not seem to work with userform.
>> I
>> placed the code in the userform activate macro, and when I press f2 it
>> does
>> not do a thing.
>>
>> Is it possible to use the function keys from a userform?
>>
>> Thanks
>> Greg
>>
>>

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      31st Jul 2008
Put This in The 'ThisWorkbook Module:

Sub SetupF2()
Application.OnKey "^{F2}", "OpenForm" 'I added the Ctrl key so Ctrl +F2
End Sub

in a standard module put:

Function OpenForm()
UserForm1.Show
End Function

HTH

"Greg B" <browgregory"nospam" wrote:

> I asked last week about access keys and I need to ask a bit more.
>
> > Sub SetupF2()
> > Application.OnKey "{F2}", "OpenForm"
> > End Sub
> >
> > Sub OpenForm()
> > UserForm1.Show
> > End Sub

>
> This was the code I was given but it does not seem to work with userform. I
> placed the code in the userform activate macro, and when I press f2 it does
> not do a thing.
>
> Is it possible to use the function keys from a userform?
>
> Thanks
> Greg
>
>

 
Reply With Quote
 
Michel Pierron
Guest
Posts: n/a
 
      1st Aug 2008
Hi Greg,
To do this, you must subclass then "Main" userform and use API functions as
follows :

For example, in a standard module:
Option Explicit
Declare Function SetWindowLong& Lib "user32" Alias _
"SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal wNewWord&)
Declare Function RegisterHotKey& Lib "user32" (ByVal hWnd& _
, ByVal id&, ByVal fsModifiers&, ByVal vk&)
Declare Function UnregisterHotKey& Lib "user32" (ByVal hWnd&, ByVal id&)
Declare Function CallWindowProc& Lib "user32.dll" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal
lParam&)

Public OldWinProc&
Public Const HOTKEY_ID& = 0
Public Const GWL_WNDPROC = (-4)

Function NewWinProc&(ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
If Msg = &H82 Then ' WM_NCDESTROY
UnregisterHotKey hWnd, HOTKEY_ID
SetWindowLong hWnd, GWL_WNDPROC, OldWinProc
ElseIf Msg = &H312 Then ' WM_HOTKEY
Call Main.HotkeyExecute
End If
NewWinProc = CallWindowProc(OldWinProc, hWnd, Msg, wParam, lParam)
End Function

Sub Test()
Main.Show
End Sub

In the Main module:
Option Explicit
Private Declare Function FindWindow& Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)

Private Sub UserForm_Initialize()
Dim hWnd&: hWnd = FindWindow(vbNullString, Me.Caption)
' Register the hotkey.
If RegisterHotKey(hWnd, HOTKEY_ID, 0&, vbKeyF2) Then
' Subclass the UserForm to watch for WM_HOTKEY messages.
OldWinProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf NewWinProc)
End If
End Sub

Sub HotkeyExecute()
Me.Hide
Sales.Show
Me.Show
End Sub

Regards,
MP

"Greg B" <browgregory"nospam"@ihug.com.au> a écrit dans le message de
news:4891b735$0$8944$(E-Mail Removed)...
>I asked last week about access keys and I need to ask a bit more.
>
>> Sub SetupF2()
>> Application.OnKey "{F2}", "OpenForm"
>> End Sub
>>
>> Sub OpenForm()
>> UserForm1.Show
>> End Sub

>
> This was the code I was given but it does not seem to work with userform.
> I placed the code in the userform activate macro, and when I press f2 it
> does not do a thing.
>
> Is it possible to use the function keys from a userform?
>
> Thanks
> Greg


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't open my Access files after conversion from Access 97 to Access 2003 M Shafaat Microsoft Access 5 10th Apr 2010 09:04 PM
Saving Access 2007 database in Access 2003 format fails in Access =?Utf-8?B?U3Bpcm8=?= Microsoft Access External Data 0 13th Aug 2006 08:37 AM
W2K3 Service w/ UNC Access, Local Disk Access, and DB Access Rob Microsoft C# .NET 6 2nd Aug 2004 01:44 PM
Access "showing images on first page only of very wide Access report. Windows XP, Access XP Jack Microsoft Access Reports 4 18th Nov 2003 03:01 PM
Re: Allowing users (w/o MS Access) to access an Access 2000 database Wayne Morgan Microsoft Access 0 29th Sep 2003 11:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:40 PM.