Newbie Autokeys help needed

  • Thread starter Thread starter endus
  • Start date Start date
E

endus

Hi,

I keep getting handed all sorts of Access related problems at work
despite the fact that I am not all that great with it, so I apologise
in advance if I am missing something obvious....I am trying to take
the opportunity to improve my knowledge of Access. The problem this
time is that I have a user who has an autokeys macro using sendkeys to
insert the current date. This key performs and needs to perform the
exact same function as CTRL+;. The problem is that sometimes
(supposedly after certain windows updates are installed) this will
blow up and cause an error. Access will say something about "Setting
up Wizards" which will inevitably crash leaving the user with the
option of repairing office. Repairing office works but we obviously
need a better solution.

I would like to be able to deliver him a solution that's better than
"tell the users to use CTRL+;". I have read online that using
SendKeys is considered kludgy and may cause problems. I have been
trying to rewrite this in a better way, but I'm not sure if it's even
possible to do it. I have seen numerous ideas on USENET on how to do
exactly this, but it always seems to have to be tied to a specific
object (definite possible confusion here). What we (apparently) need
is something that can be cut and pasted between DB's to add the same
functionality to multiple (small) DB's.

I was thinking of creating a Module like the following...

Function InsertDate(FormName As Form)
FormName.Value = Format(Now(), "mm/dd/yyyy")
End Function

The only problem is how to pass the form name from the "Run Code"
section of the autokeys macro...there doesn't seem to me to be a way
to reference whatever form/control is currently selected....this needs
to be able to insert the date basically anywhere....just free form
insert the date whereever the cursor is.

Again, I may be making huge blunders or just not understanding exactly
how all this stuff is laid out and works, but that's why I'm posting
here.

Big TIA.
~ endus ~~ at ~ endus ~ dot ~~ com ~

But what the hell. It is a good & healthy thing
to have a fine fat steak & a bottle of good Kentucky
bourbon & order cameras from Hong Kong & generally
feel rich. - Hunter S. Thompson
 
you're close, on the function. but you can't set a form's value - it has
none. btw, for proper terminology, what you posted was a procedure, not a
module. a module is the object that holds procedures.

add the following procedure to a public module, as

Public Function InsertTextDate()

On Error Resume Next
Screen.ActiveControl = Trim(Nz(Screen.ActiveControl.Text, "") _
& " " & Format(Date, "mm\/dd\/yyyy"))

End Function

create a new macro and name it AutoKeys. in design view, set the following

Name: {F5} (or whatever key or key combination you want to use)
Condition: (leave it blank)
Action: RunCode
FunctionName: InsertTextDate()

search the Access Help for "autokeys", that should give you a topic called
something like "Assign an action or set of actions to a key". there you'll
find a list of the syntax for keys and key combinations.
NOTE: what you're inserting is a text value, *not* a date/time value. so
you can use this to insert the date in a text field or memo field only. it
will append the current date to the end of the data already in the field,
without changing or deleting that existing data.
to insert today's date in a date/time field, use the following function, as

Public Function InsertDate()

On Error Resume Next
Screen.ActiveControl = Format(Date, "mm\/dd\/yyyy")

End Function

note that this code *overwrites* whatever data is already in the field, so
you can see why you might not want to use it in a text or memo field.

hth
 
you're close, on the function. but you can't set a form's value - it has
none. btw, for proper terminology, what you posted was a procedure, not a
module. a module is the object that holds procedures.

Gotcha...I knew a form had no value but I wasn't sure if we were
calling the textboxes controls or not. As far as the module, I'm
relieved to hear that we're consistent and calling the code a
procedure...I think the concept of a Module containing the procedure
is the part I don't quite grok yet. That was the part I had trouble
with with some of the code I found googling...understanding the
module/public module concept. I'll have to read up.

Tina: huge thanks. I have to nail down exactly how the user wants
this to work, but that code is exactly what I needed and both versions
work great (it just depends on which he wants). Many thanks!
~ endus ~~ at ~ endus ~ dot ~~ com ~

But what the hell. It is a good & healthy thing
to have a fine fat steak & a bottle of good Kentucky
bourbon & order cameras from Hong Kong & generally
feel rich. - Hunter S. Thompson
 
Back
Top