Subform Reference

G

Guest

I have a checkbox called CRMEM on a subform located on the main form
frmInvoice. On another subform (sbfInvoice) I have a calculation in a
textbox (txtTtlChrgs). When this calculation is less than zero, I would like
the CRMEM checkbox to appear as checked. I've referenced it in the On
Current event of the subform sbfInvoice as
Forms.frmInvoice.sbfInvoice.Form.txtTtlChrgs, but I keep getting an invalid
reference message. What am I doing wrong? The code I'm using looks like
this:

Private Sub Form_Current()
Dim Response As Variant

If Forms.frmInvoice.sbfInvoice.Form.txtTtlChrgs < 0 Then
Me.CRMEM = -1
End If

End sub
 
M

Marshall Barton

Jaybird said:
I have a checkbox called CRMEM on a subform located on the main form
frmInvoice. On another subform (sbfInvoice) I have a calculation in a
textbox (txtTtlChrgs). When this calculation is less than zero, I would like
the CRMEM checkbox to appear as checked. I've referenced it in the On
Current event of the subform sbfInvoice as
Forms.frmInvoice.sbfInvoice.Form.txtTtlChrgs, but I keep getting an invalid
reference message. What am I doing wrong? The code I'm using looks like
this:

Private Sub Form_Current()
Dim Response As Variant

If Forms.frmInvoice.sbfInvoice.Form.txtTtlChrgs < 0 Then
Me.CRMEM = -1
End If

End sub


Your logic looks ok to me, but the first itme the Current
event fires, the other subform might not be loaded yet.

I don't know how it will affect your arrangement, but try
ignoring that particular error.
 
G

Guest

I've used the OnError resume Next technique to get past this, but the value
for the checkbox tends to be "sticky". That is, it stays on the form even
when moving to different records on the main form that do not have negative
values for txtTtlChrgs. Perhaps I have not revealed all... Would it make a
difference if you knew that the record source for both frmInvoice and
sbfInvoice are the same? I simply used sbfInvoice to group the records with
the same Order Number (or Invoice Number, it's a one to one relationship).
My thinking is that whenever the form encounters a value for txtTtlChrgs that
is less than zero, that all of the grouped records would get the same value
for CRMEM. However, that does not appear to be the case. Perhaps I am not
using the right event for this procedure?
 
M

Marshall Barton

Jaybird said:
I've used the OnError resume Next technique to get past this, but the value
for the checkbox tends to be "sticky". That is, it stays on the form even
when moving to different records on the main form that do not have negative
values for txtTtlChrgs. Perhaps I have not revealed all... Would it make a
difference if you knew that the record source for both frmInvoice and
sbfInvoice are the same? I simply used sbfInvoice to group the records with
the same Order Number (or Invoice Number, it's a one to one relationship).
My thinking is that whenever the form encounters a value for txtTtlChrgs that
is less than zero, that all of the grouped records would get the same value
for CRMEM. However, that does not appear to be the case. Perhaps I am not
using the right event for this procedure?


Try using the main form's (or other subform's) Current event
to set the check box:

If Me.txtTtlChrgs < 0 Then
Forms.frmInvoice.sbfwhatever.Form.CRMEM = -1
End If
 
G

Guest

Aha! So, I got my logic backwards? Instead of using the OnCurrent event of
the subform I want to change to read the value from the other subform, you
want me to use the other subform to "push" the value of [CRMEM to the
original subform? I wouldn't have thought that would work. But I've tried
it and, so far, it appears to do the trick. It seems odd to me. Perhaps you
could explain why this is so?
 
M

Marshall Barton

Jaybird said:
Aha! So, I got my logic backwards? Instead of using the OnCurrent event of
the subform I want to change to read the value from the other subform, you
want me to use the other subform to "push" the value of [CRMEM to the
original subform? I wouldn't have thought that would work. But I've tried
it and, so far, it appears to do the trick. It seems odd to me. Perhaps you
could explain why this is so?


Well, the reason is simply that only the other subform knows
when the value needs to be updated. The original subform
doesn't know what's going on in the other subform so it has
no idea when it is supposed to reset the CRMEM control.
 
G

Guest

Cool beans! Thanks, Marshal!
--
Why are you asking me? I dont know what Im doing!

Jaybird


Marshall Barton said:
Jaybird said:
Aha! So, I got my logic backwards? Instead of using the OnCurrent event of
the subform I want to change to read the value from the other subform, you
want me to use the other subform to "push" the value of [CRMEM to the
original subform? I wouldn't have thought that would work. But I've tried
it and, so far, it appears to do the trick. It seems odd to me. Perhaps you
could explain why this is so?


Well, the reason is simply that only the other subform knows
when the value needs to be updated. The original subform
doesn't know what's going on in the other subform so it has
no idea when it is supposed to reset the CRMEM control.
 

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