Referring to Control on Subform

S

Salisha Khan

i have a form and subform. I have a control on my main form where a value
will be filled in. I have the same control on a subform and i want that
value from the main form to populate the control on the subform.
On the AfterUpdate event for the control on the main form, I have
written this code. The control on the main form(frmExpense) is named
cboVinId and on the subform(frmExpenseSubform), it is named VIN. My
question is, why isn't this working? Any help would be much appreciated!
Thanks


Private Sub cboVinID_AfterUpdate()
Forms![frmExpense]![frmExpenseSubform]![VIN] = Me.cboVinID
End Sub
 
J

Jon Furman

Salisha, I think that I know what your trouble is and it's one that confuses
a lot of people. It's important to realize that the subform control is
really just a container for the the subform that you are using. In other
words they are 2 different objects, so to reference the form that is the
subform you will need to do something more like this:

Me.frmExpenseSubform.VIN.Value = Me.cboVinID.value

Hope that fixs things up for you!

Jon Furman
 
S

Salisha Khan

Well that didn't solve my problem. Nothing happens when i type in that
code. It doesn't recognize the control VIN in my subform.

Jon Furman said:
Salisha, I think that I know what your trouble is and it's one that confuses
a lot of people. It's important to realize that the subform control is
really just a container for the the subform that you are using. In other
words they are 2 different objects, so to reference the form that is the
subform you will need to do something more like this:

Me.frmExpenseSubform.VIN.Value = Me.cboVinID.value

Hope that fixs things up for you!

Jon Furman
Private Sub cboVinID_AfterUpdate()
Forms![frmExpense]![frmExpenseSubform]![VIN] = Me.cboVinID
End Sub
 
S

Salisha Khan

ok ignore that last message. it worked. thanks

Jon Furman said:
Salisha, I think that I know what your trouble is and it's one that confuses
a lot of people. It's important to realize that the subform control is
really just a container for the the subform that you are using. In other
words they are 2 different objects, so to reference the form that is the
subform you will need to do something more like this:

Me.frmExpenseSubform.VIN.Value = Me.cboVinID.value

Hope that fixs things up for you!

Jon Furman
Private Sub cboVinID_AfterUpdate()
Forms![frmExpense]![frmExpenseSubform]![VIN] = Me.cboVinID
End Sub
 
J

Jon Furman

See I told you it was confusing, I wrote all of that and then forgot to
write in the most important part myself:

Me.frmExpenseSubform.Form.VIN.Value = Me.cboVinID.value


It's the "Form" between "frmExpenseSubform." and ".VIN" that tells it to
refer to the control that is on the subform and not the container. Sorry for
the confusion, hope that clears it up for you.

Jon


Salisha Khan said:
Well that didn't solve my problem. Nothing happens when i type in that
code. It doesn't recognize the control VIN in my subform.

Jon Furman said:
Salisha, I think that I know what your trouble is and it's one that confuses
a lot of people. It's important to realize that the subform control is
really just a container for the the subform that you are using. In other
words they are 2 different objects, so to reference the form that is the
subform you will need to do something more like this:

Me.frmExpenseSubform.VIN.Value = Me.cboVinID.value

Hope that fixs things up for you!

Jon Furman
Private Sub cboVinID_AfterUpdate()
Forms![frmExpense]![frmExpenseSubform]![VIN] = Me.cboVinID
End Sub
 
S

Salisha Khan

thanks alot jon. that did. thanks
salisha
Jon Furman said:
See I told you it was confusing, I wrote all of that and then forgot to
write in the most important part myself:

Me.frmExpenseSubform.Form.VIN.Value = Me.cboVinID.value


It's the "Form" between "frmExpenseSubform." and ".VIN" that tells it to
refer to the control that is on the subform and not the container. Sorry for
the confusion, hope that clears it up for you.

Jon


Salisha Khan said:
Well that didn't solve my problem. Nothing happens when i type in that
code. It doesn't recognize the control VIN in my subform.

Jon Furman said:
Salisha, I think that I know what your trouble is and it's one that confuses
a lot of people. It's important to realize that the subform control is
really just a container for the the subform that you are using. In other
words they are 2 different objects, so to reference the form that is the
subform you will need to do something more like this:

Me.frmExpenseSubform.VIN.Value = Me.cboVinID.value

Hope that fixs things up for you!

Jon Furman


Private Sub cboVinID_AfterUpdate()
Forms![frmExpense]![frmExpenseSubform]![VIN] = Me.cboVinID
End Sub
 

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