Connecting Tech Pros Worldwide Forums | Help | Site Map

AutoKeys Macro

ApexData@gmail.com
Guest
 
Posts: n/a
#1: Mar 23 '06
Hello

1- What is the AutoExec Macro? Is it the same thing as AutoKeys Macro?

2- I'm looking to Control Keys equally on startup for my entire app. I
understand that
the AutoKeys Macro is the place to go but it seems that some keys
cannot be
controlled there according to MS Help.
I created a Function in my form module to control my keys, but I
want to call it from
the AutoKeys macro. Will this work? Am I on the right track?
I can't seem to get it to work. I created the AutoKeys macro and put
RunCode for
the action, and ControlKeys() as the function. I put it in the
AutoKeys macro so that
it controls my entire app.

MyCode:

Public Sub Form_Key(KeyCode As Integer, Shift As Integer)
If (Shift = 6) And (KeyCode = vbKeyF8) Then
'Ctrl-Alt-F8 to open the ErrorLog
MsgBox "Ctrl-Alt-F8"
Else
'Disable choice keyboard keys
Select Case KeyCode
' ShutOff Ctrl, Alt, PgUp, PgDn, F1-F12
Case 17, 18, 33, 34, 112, 113, 114, 115, 116, 117, 118,
119, 120, 121, 122, 123
KeyCode = 0
Case Else
Me.Text6 = KeyCode
' MsgBox KeyCode, vbOKOnly
End Select
End If
End Sub


Public Function ControlKeys()
Call Form_Key
End Function


Allen Browne
Guest
 
Posts: n/a
#2: Mar 23 '06

re: AutoKeys Macro


An AutoExec macro runs once whenever you open the database.
An AutoKeys macro defines actions that should occur whenever a key is
pressed while the database is running.

You are correct in observing that AutoKeys cannot handle all keystrokes. You
will therefore need to write a function in a standard module (Modules tab of
the Database window) to provide special handling of the keystrokes. Then in
each form that needs this special handling, set KeyPreview to Yes, and use
its KeyDown event to call your generic handler, e.g.:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Call ControlKeys(KeyCode, Shift)
End Sub

Your generic key handler routine will then look like this:
Public Function ControlKeys(KeyCode As Integer, Shift As Integer)
'your code in here.
End Function

Before you go to that trouble, you are aware that you are essentially
destroying functionality that Access gives you? You might have a reason for
doing that, we often see people who are destroying useful functionality only
because they do not understand how to work with the built-in events. For
example, if you are trying to validate everything before Access saves the
record, you can just put your validation code into the BeforeUpdate event of
the *form*. Access fires this event every time before it saves the changes,
and you don't have to worry about PgDn or whatever.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<ApexData@gmail.com> wrote in message
news:1143075433.576268.207470@i40g2000cwc.googlegr oups.com...[color=blue]
> Hello
>
> 1- What is the AutoExec Macro? Is it the same thing as AutoKeys Macro?
>
> 2- I'm looking to Control Keys equally on startup for my entire app. I
> understand that
> the AutoKeys Macro is the place to go but it seems that some keys
> cannot be
> controlled there according to MS Help.
> I created a Function in my form module to control my keys, but I
> want to call it from
> the AutoKeys macro. Will this work? Am I on the right track?
> I can't seem to get it to work. I created the AutoKeys macro and put
> RunCode for
> the action, and ControlKeys() as the function. I put it in the
> AutoKeys macro so that
> it controls my entire app.
>
> MyCode:
>
> Public Sub Form_Key(KeyCode As Integer, Shift As Integer)
> If (Shift = 6) And (KeyCode = vbKeyF8) Then
> 'Ctrl-Alt-F8 to open the ErrorLog
> MsgBox "Ctrl-Alt-F8"
> Else
> 'Disable choice keyboard keys
> Select Case KeyCode
> ' ShutOff Ctrl, Alt, PgUp, PgDn, F1-F12
> Case 17, 18, 33, 34, 112, 113, 114, 115, 116, 117, 118,
> 119, 120, 121, 122, 123
> KeyCode = 0
> Case Else
> Me.Text6 = KeyCode
> ' MsgBox KeyCode, vbOKOnly
> End Select
> End If
> End Sub
>
>
> Public Function ControlKeys()
> Call Form_Key
> End Function[/color]


ApexData@gmail.com
Guest
 
Posts: n/a
#3: Mar 24 '06

re: AutoKeys Macro



"destroying functionality that Access gives you?"

Allen, is that to say that the PgUp/PgDn key in instances should be
kept on
during record Add/Edit despite my desire to to avoid scrolling to the
next record,
and then if the user does scroll to the next record it would be
prevented by the
BeforeUpdate event. Wouldn't that be 6of1 half-dozen of another? Any
suggestions
where I can find tips that expand on this topic of KeyControl and
RecordControl
during basic Add/Edit/View sessions?

I'm 3-months new to MS Access and recognize your name as one of the
biggies
of the Access Groups, and I know I speak for many when I say I am
grateful for
your knowledgeable assistance. One day, when I get it togeather with
this stuff,
I'll reciprocate.

GregRogers




Allen Browne wrote:[color=blue]
> An AutoExec macro runs once whenever you open the database.
> An AutoKeys macro defines actions that should occur whenever a key is
> pressed while the database is running.
>
> You are correct in observing that AutoKeys cannot handle all keystrokes. You
> will therefore need to write a function in a standard module (Modules tab of
> the Database window) to provide special handling of the keystrokes. Then in
> each form that needs this special handling, set KeyPreview to Yes, and use
> its KeyDown event to call your generic handler, e.g.:
> Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
> Call ControlKeys(KeyCode, Shift)
> End Sub
>
> Your generic key handler routine will then look like this:
> Public Function ControlKeys(KeyCode As Integer, Shift As Integer)
> 'your code in here.
> End Function
>
> Before you go to that trouble, you are aware that you are essentially
> destroying functionality that Access gives you? You might have a reason for
> doing that, we often see people who are destroying useful functionality only
> because they do not understand how to work with the built-in events. For
> example, if you are trying to validate everything before Access saves the
> record, you can just put your validation code into the BeforeUpdate event of
> the *form*. Access fires this event every time before it saves the changes,
> and you don't have to worry about PgDn or whatever.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> <ApexData@gmail.com> wrote in message
> news:1143075433.576268.207470@i40g2000cwc.googlegr oups.com...[color=green]
> > Hello
> >
> > 1- What is the AutoExec Macro? Is it the same thing as AutoKeys Macro?
> >
> > 2- I'm looking to Control Keys equally on startup for my entire app. I
> > understand that
> > the AutoKeys Macro is the place to go but it seems that some keys
> > cannot be
> > controlled there according to MS Help.
> > I created a Function in my form module to control my keys, but I
> > want to call it from
> > the AutoKeys macro. Will this work? Am I on the right track?
> > I can't seem to get it to work. I created the AutoKeys macro and put
> > RunCode for
> > the action, and ControlKeys() as the function. I put it in the
> > AutoKeys macro so that
> > it controls my entire app.
> >
> > MyCode:
> >
> > Public Sub Form_Key(KeyCode As Integer, Shift As Integer)
> > If (Shift = 6) And (KeyCode = vbKeyF8) Then
> > 'Ctrl-Alt-F8 to open the ErrorLog
> > MsgBox "Ctrl-Alt-F8"
> > Else
> > 'Disable choice keyboard keys
> > Select Case KeyCode
> > ' ShutOff Ctrl, Alt, PgUp, PgDn, F1-F12
> > Case 17, 18, 33, 34, 112, 113, 114, 115, 116, 117, 118,
> > 119, 120, 121, 122, 123
> > KeyCode = 0
> > Case Else
> > Me.Text6 = KeyCode
> > ' MsgBox KeyCode, vbOKOnly
> > End Select
> > End If
> > End Sub
> >
> >
> > Public Function ControlKeys()
> > Call Form_Key
> > End Function[/color][/color]

Allen Browne
Guest
 
Posts: n/a
#4: Mar 24 '06

re: AutoKeys Macro


The crucial thing it to understand how Access works, and work with it. It
might be possible to force a car stay on the road by building large, strong
fences beside every straight and around every corner, but it would be much
easier to do it by using the steering wheel that the manufacturer provided
for that purpose.

Access fires Form_BeforeUpdate for you. If you use this event, you do not
have to worry about blocking all the possible ways a records might get
saved, such as applying a filter, changing the sort order, requerying the
form, pressing Shift+Enter, choosing Save through the menu, clicking a
navigation button, closing the form, closing Access, etc etc. Just code the
validation in Form_BeforeUpdate, and forget about all those.

I doubt I have created any bound forms in the last 5 years that did not have
some code in Form_BeforeUpdate.

Hope that helps clarify what's happening, and simplifies your life.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<ApexData@gmail.com> wrote in message
news:1143217028.167935.184060@i40g2000cwc.googlegr oups.com...[color=blue]
>
> "destroying functionality that Access gives you?"
>
> Allen, is that to say that the PgUp/PgDn key in instances should be
> kept on
> during record Add/Edit despite my desire to to avoid scrolling to the
> next record,
> and then if the user does scroll to the next record it would be
> prevented by the
> BeforeUpdate event. Wouldn't that be 6of1 half-dozen of another? Any
> suggestions
> where I can find tips that expand on this topic of KeyControl and
> RecordControl
> during basic Add/Edit/View sessions?
>
> I'm 3-months new to MS Access and recognize your name as one of the
> biggies
> of the Access Groups, and I know I speak for many when I say I am
> grateful for
> your knowledgeable assistance. One day, when I get it togeather with
> this stuff,
> I'll reciprocate.
>
> GregRogers
>
> Allen Browne wrote:[color=green]
>> An AutoExec macro runs once whenever you open the database.
>> An AutoKeys macro defines actions that should occur whenever a key is
>> pressed while the database is running.
>>
>> You are correct in observing that AutoKeys cannot handle all keystrokes.
>> You
>> will therefore need to write a function in a standard module (Modules tab
>> of
>> the Database window) to provide special handling of the keystrokes. Then
>> in
>> each form that needs this special handling, set KeyPreview to Yes, and
>> use
>> its KeyDown event to call your generic handler, e.g.:
>> Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
>> Call ControlKeys(KeyCode, Shift)
>> End Sub
>>
>> Your generic key handler routine will then look like this:
>> Public Function ControlKeys(KeyCode As Integer, Shift As Integer)
>> 'your code in here.
>> End Function
>>
>> Before you go to that trouble, you are aware that you are essentially
>> destroying functionality that Access gives you? You might have a reason
>> for
>> doing that, we often see people who are destroying useful functionality
>> only
>> because they do not understand how to work with the built-in events. For
>> example, if you are trying to validate everything before Access saves the
>> record, you can just put your validation code into the BeforeUpdate event
>> of
>> the *form*. Access fires this event every time before it saves the
>> changes,
>> and you don't have to worry about PgDn or whatever.
>>
>> --
>> Allen Browne - Microsoft MVP. Perth, Western Australia.
>> Tips for Access users - http://allenbrowne.com/tips.html
>> Reply to group, rather than allenbrowne at mvps dot org.
>>
>> <ApexData@gmail.com> wrote in message
>> news:1143075433.576268.207470@i40g2000cwc.googlegr oups.com...[color=darkred]
>> > Hello
>> >
>> > 1- What is the AutoExec Macro? Is it the same thing as AutoKeys Macro?
>> >
>> > 2- I'm looking to Control Keys equally on startup for my entire app. I
>> > understand that
>> > the AutoKeys Macro is the place to go but it seems that some keys
>> > cannot be
>> > controlled there according to MS Help.
>> > I created a Function in my form module to control my keys, but I
>> > want to call it from
>> > the AutoKeys macro. Will this work? Am I on the right track?
>> > I can't seem to get it to work. I created the AutoKeys macro and put
>> > RunCode for
>> > the action, and ControlKeys() as the function. I put it in the
>> > AutoKeys macro so that
>> > it controls my entire app.
>> >
>> > MyCode:
>> >
>> > Public Sub Form_Key(KeyCode As Integer, Shift As Integer)
>> > If (Shift = 6) And (KeyCode = vbKeyF8) Then
>> > 'Ctrl-Alt-F8 to open the ErrorLog
>> > MsgBox "Ctrl-Alt-F8"
>> > Else
>> > 'Disable choice keyboard keys
>> > Select Case KeyCode
>> > ' ShutOff Ctrl, Alt, PgUp, PgDn, F1-F12
>> > Case 17, 18, 33, 34, 112, 113, 114, 115, 116, 117, 118,
>> > 119, 120, 121, 122, 123
>> > KeyCode = 0
>> > Case Else
>> > Me.Text6 = KeyCode
>> > ' MsgBox KeyCode, vbOKOnly
>> > End Select
>> > End If
>> > End Sub
>> >
>> >
>> > Public Function ControlKeys()
>> > Call Form_Key
>> > End Function[/color][/color][/color]


DFS
Guest
 
Posts: n/a
#5: Mar 24 '06

re: AutoKeys Macro


Allen Browne wrote:[color=blue]
>
> I doubt I have created any bound forms in the last 5 years that did
> not have some code in Form_BeforeUpdate.[/color]

Don't trust the users too much, eh?



Closed Thread