If Statement Referencing Sub-Forms

  • Thread starter Thread starter Dave Elliott
  • Start date Start date
D

Dave Elliott

I have two text boxes on my main form which have as there control source
controls on a sub-form on the main form.
They Reference the sub-form FTimeBillingSub
I want the code to run on another sub-form on the main form named
Vendor_List. (Main form is named TimeCards)
Right now I am trying to run the code on the get focus event of the first
control on the Vendor_List sub-form.
There is no message box. Both text boxes, text412 and text414 are in
currency format
So if Text412 has a value greater than 0 and Text414 equals 0 then MsgBox
"yada yada"
Suggestions????

If ([Text412]) > 0 And ([Text414]) = 0 Then
MsgBox "Why is there more material on this job?"
End If
 
You need to give the "path" to the other subform or the parent form.

To refer to a control on the parent form:
Me.Parent.ControlName

To refer to a control on a subform from the parent form:
Me.NameOfSubformControl.Form.NameOfControl

To refer to a control on a second subform of the parent form:
Me.Parent.NameOfSecondSubformControl.Form.NameOfControl

If you are using these in a control source, leave off the "Me.". Adjust the
names to match the control names for your situation. To refer to a subform,
you don't refer to the subform's name. You instead refer to a control on the
main form call a Subform Control. This control is a container for the
subform.
 
Error says Variable not yet created in this context in immediate window

If Me.Parent.[Text412] > 0 And [Text414] = 0 Then
MsgBox "Why is there more material on this job?"
End If



Wayne Morgan said:
You need to give the "path" to the other subform or the parent form.

To refer to a control on the parent form:
Me.Parent.ControlName

To refer to a control on a subform from the parent form:
Me.NameOfSubformControl.Form.NameOfControl

To refer to a control on a second subform of the parent form:
Me.Parent.NameOfSecondSubformControl.Form.NameOfControl

If you are using these in a control source, leave off the "Me.". Adjust
the names to match the control names for your situation. To refer to a
subform, you don't refer to the subform's name. You instead refer to a
control on the main form call a Subform Control. This control is a
container for the subform.

--
Wayne Morgan
MS Access MVP


Dave Elliott said:
I have two text boxes on my main form which have as there control source
controls on a sub-form on the main form.
They Reference the sub-form FTimeBillingSub
I want the code to run on another sub-form on the main form named
Vendor_List. (Main form is named TimeCards)
Right now I am trying to run the code on the get focus event of the first
control on the Vendor_List sub-form.
There is no message box. Both text boxes, text412 and text414 are in
currency format
So if Text412 has a value greater than 0 and Text414 equals 0 then
MsgBox "yada yada"
Suggestions????

If ([Text412]) > 0 And ([Text414]) = 0 Then
MsgBox "Why is there more material on this job?"
End If
 
"Me." is shorthand for the form that the code is running on. From the
Immediate Window you would have to specify the full path to the Parent form
instead of Me, then give the path from there if you are referring to a
subform.

Example:
Forms!frmParentForm.ControlName
or
Forms!frmParentForm.SubformControlName.Form.ControlName

Also, you need to specify the full path to both textboxes.
 
This code still does not work???
TimeCards is the main form and code is being run from a sub-form named
Vendor_List


If Forms!frmTimeCards.Text414 >0 and Forms!frmTimeCards.Text416 =0 Then
MsgBox "Why is more material being put on this job"
End If

Wayne Morgan said:
"Me." is shorthand for the form that the code is running on. From the
Immediate Window you would have to specify the full path to the Parent
form instead of Me, then give the path from there if you are referring to
a subform.

Example:
Forms!frmParentForm.ControlName
or
Forms!frmParentForm.SubformControlName.Form.ControlName

Also, you need to specify the full path to both textboxes.

--
Wayne Morgan
MS Access MVP


Dave Elliott said:
Error says Variable not yet created in this context in immediate window

If Me.Parent.[Text412] > 0 And [Text414] = 0 Then
MsgBox "Why is there more material on this job?"
End If
 
What isn't working? Are you still getting error messages or is it just not
reacting to the If as you think it should? Have you tried stepping through
the code as it runs to see what values the code thinks is in the textboxes?
Could Text416 be Null instead of zero?
 
Thanks Wayne for your help.
Found the solution, it was that the code needed to be put ahead of other
code, firing issue.
Thanks Again... Dave
 
Back
Top