How to set up a hot key (CTRL+D) for a current date

G

Guest

I have made a new macro named AutoKeys and entered ^d for the macro name,
action is SendKeys (keystrokes ^d and no for wait), Date() for comments. Two
lines under I made a RunMacro action with macro name of AutoKeys.^d in action
arguments area. When I attempt to do Control D in a date field, it does not
work. Do I need to go into form properties in design view and set it to
something? How do I make this autokey combo work? How does it know to insert
a current date, should I put a condition in the AutoKeys macro?
 
G

Guest

Ok, that works so thank you. But why won't my CTRL D using an Autokeys macro
work? How does the macro know to put in a current date without conditions
and just using keystrokes you specify? I can see this giving me problems in
the future for other custom key commands, so what is the proper way to go
about setting these things up?
 
G

Granny Spitz via AccessMonster.com

Adriana said:
But why won't my CTRL D using an Autokeys macro
work?

I think it will if you change the ^D macro's keystrokes to ^;. Your RunMacro
line two lines down isn't needed.
How does the macro know to put in a current date without conditions
and just using keystrokes you specify?

<CTRL><;> is a built in shortcut. Using these keystrokes as the action for a
sendkeys macro will call this shortcut.
 
G

Guest

So if an "auto function" for lack of a better word is already intalled, I
can't write another autokey to overwrite that? I guess I don't completely
understand how Autokeys macros work without specifying what you want it to
do. I guess it's more lines of code than just the sendkeys action.
 
G

Granny Spitz via AccessMonster.com

Adriana said:
So if an "auto function" for lack of a better word is already intalled, I
can't write another autokey to overwrite that?

Most of the time you can overwrite it. It's just that you defined your
keystrokes for your autokeys macro as if <CTRL><D> meant something. It
doesn't until you define it. Let me give you a slightly different analogy.
Say you wanted to create an autokeys macro that quit the application as soon
as you pressed <CTRL><D>. You named the macro ^D, placed Sendkeys in the
Action argument, and typed ^D for the keystrokes and saved the macro.

Now you open a form and when you're finished with it, you want to close
Access so you press <CTRL><D>. Nothing happens because <CTRL><D> doesn't
mean *close the application.* It means "press these keys" as per your action
argument and the keys you identified in your autokeys macro are <CTRL><D>.
So the computer executed those keys for you, just like you programmed it to.

This is called a circular reference, much like if you looked up a word in the
dictionary and found the definition was the word you'd looked up:

obviate vt [LL obviatus, pp of obviare, fr L obviam] (1598): to obviate.
I guess it's more lines of code than just the sendkeys action.

Most of the time it's one of the other actions like OpenForm or
TransferSpreadsheet, but if you use Sendkeys you have to supply the sequence
of keystrokes that has a defined meaning. <CTRL><;> is a built in shortcut
that does exactly what you wanted, paste the current date in a text box.
 
G

Guest

So under the SendKeys action, the next sequence would be SetValue with
expression of Date() and in the item, you call out the field that you want to
use that date function in? That's what the error message is telling me, that
I need to list the table and field name. I know you told me to use Control;
, but I want to overwrite this with Control D as an example to see if it
works for future macros to be written. In your example, you said that just
using CTRL+D without defining it will not do anything, there must be
subsequent actions. So I guess what I'm asking if what are the steps to
identifying autokeys? Sorry to be a pain.

Granny Spitz via AccessMonster.com said:
Adriana said:
So if an "auto function" for lack of a better word is already intalled, I
can't write another autokey to overwrite that?

Most of the time you can overwrite it. It's just that you defined your
keystrokes for your autokeys macro as if <CTRL><D> meant something. It
doesn't until you define it. Let me give you a slightly different analogy.
Say you wanted to create an autokeys macro that quit the application as soon
as you pressed <CTRL><D>. You named the macro ^D, placed Sendkeys in the
Action argument, and typed ^D for the keystrokes and saved the macro.

Now you open a form and when you're finished with it, you want to close
Access so you press <CTRL><D>. Nothing happens because <CTRL><D> doesn't
mean *close the application.* It means "press these keys" as per your action
argument and the keys you identified in your autokeys macro are <CTRL><D>.
So the computer executed those keys for you, just like you programmed it to.

This is called a circular reference, much like if you looked up a word in the
dictionary and found the definition was the word you'd looked up:

obviate vt [LL obviatus, pp of obviare, fr L obviam] (1598): to obviate.
I guess it's more lines of code than just the sendkeys action.

Most of the time it's one of the other actions like OpenForm or
TransferSpreadsheet, but if you use Sendkeys you have to supply the sequence
of keystrokes that has a defined meaning. <CTRL><;> is a built in shortcut
that does exactly what you wanted, paste the current date in a text box.
 
G

Granny Spitz via AccessMonster.com

Adriana said:
So under the SendKeys action, the next sequence would be SetValue with
expression of Date() and in the item, you call out the field that you want to
use that date function in?

You would have to name the form or report and the field in the Item argument
like this: [Forms]![frmOrders]![OrderDate] but that would be very limiting.
You could only use it for *that* form and field. You would have to define
another autokey macro if you needed the same functionality on frmReturns and
frmShipments, etc.
So I guess what I'm asking if what are the steps to
identifying autokeys?

I'm not sure I understand your question of "identifying" (or explaining)
autokeys as opposed to defining keystrokes for Sendkeys. Autokeys is pretty
powerful for non-programmers. You can execute the most common methods like
opening forms, importing or exporting spreadsheets, etc. There's a few
actions that give you more custom functionality, like Sendkeys, SetValue and
RunCode.

Sendkeys gives you some flexibility but it can be a double edged sword.
Whatever has the focus is going to get these keystrokes. SetValue is very
specific in which control and which object is going to get a value, but it's
very limited in that you can only use that autokey on that one object and
control. Something that can give you much more flexibility and include error
handling is RunCode which allows you to run a built in function or a public
function you write yourself.

Sorry to be a pain.

Don't worry. If you understand this then not only will you not have any
further problems, but you'll be able to teach others too.
 
S

Steve Schapel

Adriana,

It looks to me like there are two areas of confusion here.

First of all, somebody in Microsoft should apologise for the fact that a
macro, or macro group, has a name (this is the name of the macro you
would see in the database window when you look under the Macros tab),
and also in the macro design window there is a Macro Name column where
each macro within the macro group can be given a name. See, told you it
was confusing :) .

To set up an AutoKeys macro, you need to name the macro group (i.e. the
actual macro object) as AutoKeys.

Secondly, there is the question of how to make a macro write the date
into a control. The SendKeys action is not the way to go here.
Generally SendKeys should be avoided anyway. But in any case, there is
no way SendKeys can process the current date. You would need to use a
SetValue action.

So, Granny Spitz is absolutely correct, you should use the built-in
Ctrl+; shortcut anyway, there is no advantage in constructing another
shortcut for the same purpose.

But out of interest, this is all you would have needed in order to do it
(i.e. it is simpler than you thought!)...

Make a macro, and in the Macro Name column enter...
^d
.... and in the Action column, enter...
SetValue
.... and enter these arguments for the SetValue
Item: [Screen].[ActiveControl]
Expression: Date()

Close the macro and save it as AutoKeys.

Hope that makes a bit more sense now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top