problem with Subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Please, help!!!

I have a combo on my main form with the following event procedure:
Private Sub Paid_AfterUpdate()
If Me.Paid = Me.[Paid].Column(0) Then
Me.Address = Me.[Paid].Column(1)
End If
End Sub

This works all right.
I want a similar thing on my sub-form, but I cannot make it out right. I
guess that reference to the subform is wrong, but I have no idea how to do it
right:

Private Sub Combo32_AfterUpdate()
If Me!Forms!SPENT!Child37![Description] =
Me!Forms!SPENT!Child37![Description].Column(0) Then
Me!Forms!SPENT!Child37![Unit Price] =
Me!Forms!SPENT!Child37![Description].Column(1)
End If
End Sub

Please help me!!!!

Thank you.
Lana
 
Lana,

Since both controls reside within the subform, the references should be
local:

Me!Combo32
Me!UnitPrice

Also, you seem to have a wrong reference: if the event is called
Combo32_AfterUpdate, then I suppose the combo's name is Combo32, not
Description, which is a good reason why your code wouldn't work!

So, the code should look like:

Private Sub Combo32_AfterUpdate()
Me![Unit Price] = Me!Combo32.Column(1)
End Sub

Finally, notice that I have removed the If / Then structure; it is
redundant, since a control will always be equal to itself (assuming that the
bound column of the control is the first one / index 0). The same holds true
for your other similar procedure.

HTH,
Nikos
 
Thank you Nikos!

I am so stupid! Of cause it should be the combo name, not the field name!

And I was using the "if/then" because I thought it must be different for the
case when my combo is not bound to list. I thought I have to compare actual
values entered into the combo with the values from the list, and if they were
similar, then use second column to populate the "Price" text-box.

Seems I was wrong, cause I see it works no problem without if/then.

Thank you again!

Lana

Nikos Yannacopoulos said:
Lana,

Since both controls reside within the subform, the references should be
local:

Me!Combo32
Me!UnitPrice

Also, you seem to have a wrong reference: if the event is called
Combo32_AfterUpdate, then I suppose the combo's name is Combo32, not
Description, which is a good reason why your code wouldn't work!

So, the code should look like:

Private Sub Combo32_AfterUpdate()
Me![Unit Price] = Me!Combo32.Column(1)
End Sub

Finally, notice that I have removed the If / Then structure; it is
redundant, since a control will always be equal to itself (assuming that the
bound column of the control is the first one / index 0). The same holds true
for your other similar procedure.

HTH,
Nikos

Lana said:
Please, help!!!

I have a combo on my main form with the following event procedure:
Private Sub Paid_AfterUpdate()
If Me.Paid = Me.[Paid].Column(0) Then
Me.Address = Me.[Paid].Column(1)
End If
End Sub

This works all right.
I want a similar thing on my sub-form, but I cannot make it out right. I
guess that reference to the subform is wrong, but I have no idea how to do it
right:

Private Sub Combo32_AfterUpdate()
If Me!Forms!SPENT!Child37![Description] =
Me!Forms!SPENT!Child37![Description].Column(0) Then
Me!Forms!SPENT!Child37![Unit Price] =
Me!Forms!SPENT!Child37![Description].Column(1)
End If
End Sub

Please help me!!!!

Thank you.
Lana
 
Back
Top