Customizing one Function key changes all function keys

smercer

Registered User.
Local time
Today, 22:05
Joined
Jun 14, 2004
Messages
442
Hi all

I am customizing the function keys and soon found that all the function keys have changed.

the function keys are going to do different things in different forms and need to not have global shortcut keys (most of the time).

here is my code:
Code:
If KeyCode = vbKeyF11 Then
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "udt_Variables_Previous_Form_Book_Entry"
    DoCmd.SetWarnings True
    DoCmd.OpenForm "frm_Find_Book" 'will open the datasheet "frm_Find_Book" into a new window
    Me.sfrm_Book_Entry_Book_Description_Record_selected.Form.RecordSource = "qry_Book_Entry_Book_Description_Find_Book_Record_Selected" 'will change source in sfrm_Book_Entry_Book_Description_Record_selected to "qry_Popup_Record_Selected"
    sfrm_Book_Entry_Book_Description_Record_selected.Requery
    sfrm_Book_Entry_Book_Description_in_Store_Index.Visible = False 'will hide the form "sfrm_Book_Entry_Book_Description_in_Store_Index"

    Else
    If KeyCode = vbKeyF12 Then
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "udt_Variables_Correct_Pass_True"
        DoCmd.SetWarnings True
        DoCmd.OpenForm "frm_Book_Sales" 'will open the "frm_Book_Sales" form

        DoCmd.Maximize 'this will Maximize the "frm_Book_Sales" form
        Forms!frm_Book_Sales!Book_ID_Lookup.SetFocus 'sets the focus to Book_ID_Lookup in form "frm_Book_Sales"
        DoCmd.Close acForm, "frm_Book_Entry_form", acSaveYes 'this will close "frm_Book_Entry_form" saving any data not already saved
    End If
End If

Can anyone help?

Thanks in advance
 
If I understand your question, why are all the keys changing when you reset just one, I'm not sure why, but, may I suggest you use a select case instead of if else in your code.

Also, and you may already be planning on doing this, but I think I would do a seperate subroutine for each set of key configurations, including one to set them all to a 'No Action' state, and call these subroutines were appropriate.

???
kh
 
KenHigg said:
If I understand your question, why are all the keys changing when you reset just one

I Must have changed something because only one button worked ...for a while. Now access only uses default actions for all function buttons (even before converting to select case)

KenHigg said:
I'm not sure why, but, may I suggest you use a select case instead of if else in your code.

I took your suggestion and is the same as before. Here is how it is now:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyF5
      Me.sfrm_Book_Entry_Book_Description_Record_selected.Form.RecordSource = "qry_Book_Entry_Book_Description_Select_record"
   DoCmd.Close acForm, "frm_select_Book"

Case vbKeyF11
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "udt_Variables_Previous_Form_Book_Entry"
        DoCmd.SetWarnings True
        DoCmd.OpenForm "frm_Find_Book" 'will open the datasheet "frm_Find_Book" into a new window
        Me.sfrm_Book_Entry_Book_Description_Record_selected.Form.RecordSource = "qry_Book_Entry_Book_Description_Find_Book_Record_Selected" 'will change source in sfrm_Book_Entry_Book_Description_Record_selected to "qry_Popup_Record_Selected"
        sfrm_Book_Entry_Book_Description_Record_selected.Requery
        sfrm_Book_Entry_Book_Description_in_Store_Index.Visible = False 'will hide the form "sfrm_Book_Entry_Book_Description_in_Store_Index"

Case vbKeyF12
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "udt_Variables_Correct_Pass_True"
        DoCmd.SetWarnings True
        DoCmd.OpenForm "frm_Book_Sales" 'will open the "frm_Book_Sales" form

        DoCmd.Maximize 'this will Maximize the "frm_Book_Sales" form
        Forms!frm_Book_Sales!Book_ID_Lookup.SetFocus 'sets the focus to Book_ID_Lookup in form "frm_Book_Sales"
        DoCmd.Close acForm, "frm_Book_Entry_form", acSaveYes 'this will close "frm_Book_Entry_form" saving any data not already saved
End Select

End Sub


KenHigg said:
Also, and you may already be planning on doing this, but I think I would do a seperate subroutine for each set of key configurations, including one to set them all to a 'No Action' state, and call these subroutines were appropriate.

???
kh

I am planing on doing that but I prefer to test the code without needing to put in the long bits of code so I have less code to go through.

Is it important that the keydown event is in the main form or the subform? because I want to use it in the main form, but also need it in the sub form
Thanks for helping
 
Last edited:
I would think it would depend on which on has focus. Another reason to place it in a sub and and call it from both (I may be wrong here, I'm really just guessing as I don't think I have ever tinkered with the function key stuff!)

kh
 
Hi ken

It does depend on which has focus (after testing).

I think what I changed before was the deletion of the macro autokeys.

I am now creating a new autokeys macro, but I still don't know how to make each key work differently in different forms.

I have created a function in vb so that all action lines in the macro calls the same function and from there it runs the function for that form. It than has a select case for each function key pressed.

May be I should try having a new line per form per button in the macro. how would I acheive this?
 

Users who are viewing this thread

Back
Top Bottom