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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I reprogam the F12 button? 3

Status
Not open for further replies.

BobLoblaws

Programmer
Nov 20, 2001
149
CA
By default, F12 opens some quicksave window in access.
I would like to program the F12 to open my custom search form. Does anyone have any idea how to do this?
Do I have to hook the keyboard?
 
Use an AUTOKEYS macro.

Code the F12 key in the macro to open your search form - the notation for an F-key in the macro is {f-key}, e.g. {F12}. The macro name would be {F12} and the action would be OpenForm.


Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
 
This is mostly working, but I don't understand why I keep getting the error:

"The expression you entered has a function name that Microsoft Access can't find."

That's all I get. I have checked to make sure the name is correct, by copying and pasting. Have tried numerous different ways of calling the function...including the use of Forms![MyForm]![Function] substituting the bang for a dot, etc.

In the macro the Function dialog is correct according to Access Help..."Function()". If I leave out the parentheses, I get a different error, stating that I have called a control that isn't in the current object.

I'm really confused. What am I missing?

-Dan
 
V Inn, did we miss something? Is your post relevant to AutoKeys macros? What exactly are you talking about?...

1) WHERE is the function? In a standard module? It needs to be to be global.

2) are you setting a variable to the result of the function?

Foo = MyFunction(11111)

Are you trying to run a function on an object event in a form?

OnEnter: =MyFunction()

?????


Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
More Neat Access stuff at
 
sorry about that...let me try again.

I'm using an autokeys macro to perform the same action as when you click the 'save' button on my form.

Clicking the save button on my form calls two subs.
WriteRecord and HandlecmdSave

I have added a function to the module in my form (this may be where I am going wrong) that calls the same two subs...WriteRecord and HandlecmdSave when you hit the desired key from my AutoKeys macro. (I also tried calling the sub "cmdSave_Click" to no avail either)

So my question is: What do I need to do, or where do I need to put my function so that it will be called when I hit the key in my AutoKeys macro?

Does that explain it better?
Thanks in advance.
-Dan
 
Kind of. I think. Maybe...[smile]

WriteRecord and HandleCmdSave probably need to be in a standard module if you want them to be callable from ANY form or other object.

If they're generic enough, you should be able to do this.

What do these two functions do? There might be an easier way....

Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
More Neat Access stuff at
 
Thanks for sticking with me...

WriteRecord - examines the fields in the form for validity and then writes a record to my table if the entries are good.

HandlecmdSave - enables or disables the 'Save' button on my form depending on what information is filled in on the form.

Should I move these two Subs out of the class module they are in that is associated with the form? or should I move the function out of the class module.

From what I could gather from Acc Help the Run Code action in a macro should work on my function...

(quote access help)
If you use the RunCode action to call a function, Microsoft Access looks for the function with the name specified by the Function Name argument in the standard modules for the database. However, when this action runs in response to clicking a menu command on a form or report or in response to an event on a form or report, Microsoft Access looks for the function first in the form's or report's class module and then in the standard modules.
(end quote)

Am I not really following this rule because my action is hitting a key?
 
Ok, your problem here is going to be whether or not WriteRecord is "form specific", e.g. do you refer to specific fields and do fancy evaluations? If so, then as you can imagine, the function won't work unless it's in the form module, without some modifications.

So even if you put it in a standard module, it might not work right.

But even so, you should be able to call it from an f-key somewhere, as long as you pressed that f-key ONLY when you were in the form that WriteRecord was in...

For example, I have a function key that centers a control horizontally. It runs whenever I press F11. If I'm in a form or report design and press F11, everything works fine. If I'm not, it gets ignored...

Code:
Function CenterIt()
'
' this function will center (horizontally)
' a control on a form or report
' called via F11 during design process, 
' F11 is in AutoKeys macro
'
On Error Resume Next

 Set FControl = Screen.ActiveForm
 Set RControl = Screen.ActiveReport

'* Get this form's name
 L_name = Screen.ActiveForm.Name
 
'A form is active...
If L_name <> &quot;&quot; Then
 L_fWidth = FControl.Width
 L_cWidth = Screen.ActiveControl.Width
 Screen.ActiveControl.Left = (L_fWidth / 2) - (L_cWidth / 2)
Else
' ok, then a Report is active....
L_name = Screen.ActiveReport.Name
    If L_name <> &quot;&quot; Then
        L_fWidth = RControl.Width
        L_cWidth = Screen.ActiveControl.Width
        Screen.ActiveControl.Left = (L_fWidth / 2) - (L_cWidth / 2)
    End If
End If

Set FControl = Nothing
Set RControl = Nothing

End Function

My Autokeys macro just has F11 issue the RUNCODE command, with &quot;CENTERIT()&quot; as the function name.

Are we getting closer?

Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
More Neat Access stuff at
 
I think we are really close, and I think it's not working because of some references issue or just an Access quirk.

Looking at your example, mine is much the same. I have tried a few different things (most of my coding is trial and error anyway). I'll post first what I have and then what I have tried.

In the module behind my form (OTC_Entry):
Code:
Function SaveRecord()

    WriteRecord
    HandlecmdSave

End Function

My macro is just like yours...
It's named &quot;AutoKeys&quot;
The 'key' in question is &quot;^M&quot; or {F12}, I have tried both, alternatively.
The function is &quot;SaveRecord()&quot;

When I run this I get the error I mentioned in my confusing post above.

I have tried setting the AutoKeys macro to run another macro which in turn performs &quot;run code&quot;, same result. I have tried making changes to my code, but that doesn't matter because I'm not even getting that far along...the macro claims it can't find the function let alone error on the code in the function.

I'm going to try saving, closing, repairing and compacting my DB once I return from lunch. Maybe the break will provide some inspiration. I'll post results.
Thanks again
-Dan
 
Ok, well I thought about it, and didn't come up with anything new.

I have closed and opened, compiled my module, compacted the db, repaired it, and tried other syntaxes.

Nothing has worked yet.

I know my function is valid, because I have adjusted the code for the Click action of the Save button...instead of calling the subs directly, it calls my function...everything else seems to be working.

I will continue to play with this, and see what I can get. Do I need to declare the function or a special variable in some way other than just &quot;Function SaveRecord()&quot;?
Thanks again-
-Dan
 
I went home last night frustrated with this...thought I would try it on my Acc 2k installation at home and see whether I got a different result...nope. Same thing.

Evidently I am doing something wrong. I will continue to persist, but if anyone else has any ideas.

Thanks again WildHare / Ex-JimAtTheFAA!
-Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top