problem synchronizing a data entry form

G

Guest

Greetings,
I am trying to synchronize a data entry form (Me) so that when the data
entry form opens, the "StudyID" value from a control on a subform
"sfrmEPStudy" of "frmMaster" is placed into the "StudyID" control on the data
entry form. The code shown below uses the "on open" event of the data entry
form. It first confirms that frmMaster is open which works fine. The problem
I'm having seems to be having it find the value of the "StudyID" control on
the subform "sfrmEPStudy". The code below givea me "Run-time error 424:
Object Required".

Private sub Form_Open(Cancel As Integer)
If IsOpen("frmMaster") Then
Me.StudyID.DefaultValue = frmMaster!sfrmEPStudy.Form!StudyID
End If
End Sub

If I plug a dummy value in, that dummy value is successfully placed into the
"studyID" control on the data entry form for example substituting:

Me.StudyID.DefaultValue = 19

Into the above code sets the StudyID control on the data entry form to "19".
Thanks for any help.
 
S

Steve Schapel

Steve,

You need Forms! in front of the expression, like this...
Me.StudyID.DefaultValue = Forms!frmMaster!sfrmEPStudy.Form!StudyID

You might also consider just placing the value in the control itself,
rather than the somewhat circuitous route of using the Default Value
property, i.e....
Me.StudyID = Forms!frmMaster!sfrmEPStudy.Form!StudyID
 
G

Guest

Hi

Thank you for your prompt reply.

Me.Study = Forms!frmMaster!sfrmEPStudy.Form!StudyID

gives me a different error:

Run-time Error '2465': Microsoft Access can't find the field 'sfrmEPStudy'
referred to in your expression.

What does it mean it can't find the "field"? Does it think the sub-form
'sfrmEPStudy' is a form object?

Steve
 
S

Steve Schapel

Steve,

No, it thinks that sfrmEPStudy is a control on the frmMaster form. Is
it? The name of the subform control is not necessarily the same as the
name of the form that is used for the subform. If these two names are
different for some reason, then it is the name of the subform control on
the main form that the code needs to use.
 
G

Guest

Yup, that was the problem! And that's not the first time I've missed that.
Thanks.

Steve
 

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