Order of events for default value

G

Guest

Can anyone help with updating two controls on a form where each gets it's
default value from a separate form? I can get each to work separately, but
can't get them to work together. I set this up in a macro, but here is the
converted module:

Function SetTaskWorker1()
On Error GoTo SetTaskWorker1_Err

DoCmd.OpenForm "Auto_Add Activity to a Task", acNormal, "", "", , acHidden
Forms![Auto_Add Activity to a Task]!Task = Forms![Auto_Update
Task]![Task Number]
DoCmd.OpenForm "TaskWorker", acFormDS, "", "", , acHidden
Forms![Auto_Add Activity to a Task]![Task Worker] =
Forms!TaskWorker![Task Worker]


SetTaskWorker1_Exit:
Exit Function

SetTaskWorker1_Err:
MsgBox Error$
Resume SetTaskWorker1_Exit

End Function

My main form is named [Auto_Update Task]
Subform is named [Auto_Add Activity to a Task]
The two controls are on the subform.
I'm currently calling the macro from the On Open event of the main form. It
is updating the Task Number, but not the Task Worker.

Any advice appreciated!
 
V

Van T. Dinh

If by "Subform", you actually meant Access Subform (a Form inside another /
bigger Form) then you don't open the Subform with the OpenForm Method. The
Subform is opened automatically when you open the (Main) Form.

If you meant a secondary Form (which is opened separately from the Form
"Auto_Update Task" then I would recoomed change the order of the statements
around with a bit extra like:

DoCmd.OpenForm "TaskWorker", acFormDS, "", "", , acHidden
DoCmd.OpenForm "Auto_Add Activity to a Task", acNormal, "", "", ,
acHidden
DoEvents
Forms![Auto_Add Activity to a Task]!Task = _
Forms![Auto_Update Task]![Task Number]
Forms![Auto_Add Activity to a Task]![Task Worker] = _
Forms!TaskWorker![Task Worker]

OTOH, I am not sure how you know that the CurrentRecord on the Form
"Auto_Update Task" is the correct Task to copy to the Form "Auto_Add
Activity to a Task". The same problem for the Form "Task Worker" and since
the Form is hidden, no one will be able to change the CurrentRecord to the
correct Task Worker.

HTH
Van T. Dinh
MVP (Access)
 

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