Change Macro to Code

G

Guest

Hello,

We have a system that was developed in Access by a summer student several
years ago. We are having a problem with one of our functions that calls a
macro. There are some SendKeys actions in the macro that have the Wait
option set to "Yes" but the waiting is not long enough so we are running into
problems with the macro "getting ahead of itself." This is what an Access
developer suggested.

So we want to convert the macro to code.

This is what needs to be done:
- change the value of two fields of the current record being displayed in
the form
- make a duplicate record of that record and change two fields in that record
- display the new record in the form

So, in the On Click event of the button, we need to choose Event Procedure
and add the code. I can get that far, but we do not have in-house Access
knowledge. So I am stuck as to what commands to use to make these changes
described above. How do I refer to the table in the code? How do I refer to
the current record? How do I change the values in the appropriate fields?
How do I copy the record and add a duplicate record, position the record
pointer to the new record and change the values in the appropriate fields?

I expect that if I simply convert the Macro to code, the SendKeys function
will still present problems.

In a language that I am familiar with, I could do these things in minutes.
But I don't know how to do it in Access and the programmer that we consulted
said it would cost several hours in labour. We are non-profit and can't
afford it. Any help would be appreciated.

Thanks,

Joe
K-W Humane Society
 
G

Guest

What you are trying to sounds very weird and not something you should need to
do in a well-designed application. So I suspect there is another answer to
your problem than the solution you are proposing. What does this application
do? What is the particuler operation you are trying to modify?
Ideally all macros should be converted to code and there is a wizard that
will do that for you. Type 'convert macro' into the Help system and it will
tell you how to do this. Its difficult to do much in Access without Visual
Basic knowledge.

-Dorian
 
G

Guest

Type 'Convert Macro' in the Access Help system and it will tell you how to do
the first step.
Once you have this converted to code, it sounds like the code needs to be
changed to not use the 'sendkeys' function.
What version of Access are you using?

-Dorian.
 
G

Guest

We are using Access 2003.

Here is the converted macro:

*********** START ***************
DoCmd.Hourglass True
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenQuery "Animal Moving Super", acViewNormal, acEdit
DoCmd.RunCommand acCmdRecordsGoToFirst
DoCmd.RunCommand acCmdFind
SendKeys "{tab}{tab}{tab}~", True
SendKeys "Hold{tab}", True
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdPaste
SendKeys "Stray History{tab}", True
SendKeys "{F2}{END}{BACKSPACE}{H}{TAB}", True
DoCmd.RunCommand acCmdCopy
DoCmd.Hourglass False
DoCmd.Close acQuery, "Animal Moving Super"
Exit Function
*********** END ***************

The SendKeys commands basically just make the necessary changes to the data.
We want to make the changes without using SendKeys (replace it directly in
the table).

Can you point me in the right direction?

Thanks,
Joe
 

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