Full Version: Can I use key inputs to control behaviour
UtterAccess Forums > Microsoft® Access > Access Forms
skelly
I have a form that inputs data into a table just fine. However in this database I want it to emulate an old green-on-black database as it will eventually replace this old one.
would like to have a label on the form, that says "F2 to SAVE" "F3 to QUIT" and have the form react in that way if the appropriate keys are pressed.
Is this possible? If so How??
Many thanks in anticipation.
Ian
freakazeud
Hi,
sure...have a look at the AutoKeys macro. Search for it in Access help to get sample syntax. This will globally overwrite the behavior of the keys. Adding the labels should be no problem, right?
HTH
Good luck
HiTechCoach
One method would be to use the autokeys macro to reassign the keys.

I would probably use the key press event of the form to trap the keys and then it call the desired code. This way it only overwrites the Access standard key usages for this form.

Edited by: HiTechCoach on Tue Aug 14 10:24:01 EDT 2007.
t0nka
Put this code into the KeyPress Event of your form.
If KeyAscii = vbKeyF2 Then
DoCmd.RunCommand acCmdSaveRecord
End If
If KeyAscii = vbKeyF3 Then
Docmd.Quit
End If
HTH
t0nka
skelly
Wow you guys are quick.
any thanks to all of you. I will give it a go and see what happens. Thanks Freakazeud I can do the label no problem, I will post back and let you all know how it goes.
Many thanks,
Ian
HiTechCoach
You're welcome!
Glad we could assist.
uarulez2.gif
freakazeud
You're welcome.
Good luck!
skelly
Hi,
Well I think I must have been close several times but no cigar. I used the Macros tool and entered F2 then set the action to SAVE. In the Form properties I set the 'On Key Press' field to the name of the macro, but still no success.
Otried the Code supplied, using 'Event Procedure' and that didn't work either, even more strange though was that whenever a letter 'r' or 'R' was entered in any of the textboxes, the database quit??
Any ideas on where I am going wrong?
Many thanks,
Ian
freakazeud
Did you look up AutoKeys in the Help files?
Once you save the macro with the name AutoKeys the shortcuts you provided should function. There is no need for code or for referring to the macro any place. The syntax within macro design would be something like:
acro Name___Action___Comment
{F2} ___ RunCommand ___ This is sample
HTH
Good luck
skelly
Hi Freakazeud,
looked it up and came up with ALMOST what you have there
Macro Name___Action___Comment
{F2} _____ SAVE_____Save Record
Then I selected 'Autokeys' from the options available in form properties, 'On Key Press'.
Is the problem because I selected 'SAVE' ?
I will go away and try the RunCommand.
Aghhhhh I have just seen the light. I need to do this for the properties of the command button, not for the form, Right?
Many thanks,
Ian
freakazeud
As mentioned you do not need to specify anything at the form/control level after you have saved the macro with name AutoKeys. Just open a form do some changes to a record and press the F2 key. It should execute the action. You can try it out with a msgbox as the action in the macro. After you saved the macro with the AutoKeys name hit the F2 key and you should see the msgbox appear. I think you want the RunCommand action with the SaveRecord argument.
HTH
Good luck
skelly
Eureka, I'm not sure what I was doing wrong before, but it is now working just as it should, I have also added a message which pops up confirming the record has been saved.
any thanks for your patience freakazeud.
Ian
freakazeud
You're welcome.
Glad you got it sorted out.
Good luck on future projects!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.