transfering data automatically from one form control to another fo

S

Sarah at DaVita

I have a form that has a button to open another form. This form opens to a
specific record depending on what MSA_LeNum they choose in the first form.
It is possible that the LeNum does not exist in the table used by the
subform. I want access to enter the LeNum from the first form into the
control on the subform - in essense add the record. In the on open event in
the sub form I added the following code which does not work. The LeNum is a
key in the subform. Can someone tell me what I have wrong here. I am very
new to this stuff. Thanks.

Private Sub Form_Open(Cancel As Integer)
If Me.LE_Num <> [MSA_Inquiry_frm.MSA_LeNum] Then
Me.LE_Num = [MSA_Inquiry_frm.MSA.LeNum]
Else
Me.LE_Num
End If
 
J

John W. Vinson

I have a form that has a button to open another form. This form opens to a
specific record depending on what MSA_LeNum they choose in the first form.
It is possible that the LeNum does not exist in the table used by the
subform. I want access to enter the LeNum from the first form into the
control on the subform - in essense add the record.

If you're "opening" the form then it is not a subform! A Subform sits in a
"subform control" on a mainform, and automatically inherits the value in its
Master Link Field. Could you make the second form a Subform, and use MSA_LeNum
the Master and Child Link Field? Then it would inherit automatically, without
any code at all.

If you do need to use a popup form, I'd suggest setting the DefaultValue of
Me.LE_Num rather than populating the field. Your <> comparison will NOT work
if the form is empty; you might be able to use

If Me.NewRecord Then

instead of your inequality test.
In the on open event in
the sub form I added the following code which does not work. The LeNum is a
key in the subform. Can someone tell me what I have wrong here. I am very
new to this stuff. Thanks.

Private Sub Form_Open(Cancel As Integer)
If Me.LE_Num <> [MSA_Inquiry_frm.MSA_LeNum] Then
Me.LE_Num = [MSA_Inquiry_frm.MSA.LeNum]
Else
Me.LE_Num
End If

John W. Vinson [MVP]
 
S

Sarah at DaVita

Well duh. I should have thought to do that. It's a forest and tree issue.
Thanks!!
 
Top