Stop a macro from calling itself

S

Sandra

Hi Have the following OnFocus event on my form:

Private Sub CourseID_GotFocus()

DoCmd.RunMacro "macro.Requery", 1
Me.Amt.SetFocus

which gives me an error:
A macro can call itself a maximum of 20 times

The macro is a simple Requery with no control specified.

I am not sure why the macro is running more than once, since I specified the
Repeat Count as 1. There is not event behind the Amt field that would bring
the focus back to the Course_ID field and cause the macro to run again.

I have also tried the following, which works...

Private Sub Amt_GotFocus()
DoCmd.Requery

.... but it iterates for a few seconds before it shows the final values.

Basically, I have a calculation on one form that updates records on another
form, but the second form does not show the new record unless I manually
press F5. I am trying to get the second form to update using a refresh macro.

Many thanks for your help!
 
D

David H

1) Never, Never, Never use macros unless its an Autoexec() to fire off code
at startup.

2) What specific control is being requeried? Are you dealing with any
subforms or form/subforms showing continuous records?
 
J

Jack Leach

A Requery of the form may be resetting the focus to that control behind the
scene's which would fire the event again. I generally try to avoid using the
Got/Lost Focus events and Exit/Enter events... usually you can use the Update
or Change events and get the desired results without having to worry about
stuff like this happening.

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
P

Paolo

Hi Sandra,
I suppose that CourseID is the first control in the tab order of your form
so everytime you requery your form CourseID get focus and so it fires again
the macro.
It's better if at the end of your calculation you requery your subform in
this way:

forms!thenameoftheform!thenameofthesubform.form.requery

HTH Paolo
 
S

Sandra

Thanks all!

I solved this so simply following Jack's suggestion:

Private Sub Courses_Registered_by_Student_Enter()
DoCmd.Requery

End Sub

regards,
sandra
 

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

Similar Threads


Top