This code is just meant to figure out a total and then a percentage of that total, and then display the percentage amount in a textbox. This code runs when a button on a form is clicked, but it uses data based in a subform on that form, and the textbox that it should display to is on the form. Both the form and the subform are invoked in the class list, so it confuses me as to why it comes up with an “Object Required” error.
Private Sub cmdTest_Click()
'Initialisation
Dim TotalAmount As Integer
Dim GiftAid As Integer
'Processing
If AllForms!frmGiftAid!subfrmqryGiftAid!PaymentIncrement Is Not Null Then
If AllForms!frmGiftAid!subfrmqryGiftAid!PaymentIncrement = "Monthly" Then
TotalAmount = _
(AllForms!frmGiftAid!subfrmqryGiftAid!PaymentAmountPerIncrement * 12)
Else
TotalAmount = _
AllForms!frmGiftAid!subfrmqryGiftAid!PaymentAmountPerIncrement
End If
End If
'Termination
GiftAid = (TotalAmount * 0.25)
AllForms!frmGiftAid!subfrmqryGiftAid!subfrmqryGiftAidtxtGiftAid = GiftAid
End Sub
The line that the error occurs on is the first one that references the subform, so it’s:
If AllForms!frmGiftAid!subfrmqryGiftAid!PaymentIncrement Is Not Null Then
I’ve tried using different variations of the code to reference the subform (just referencing the subform, using “Forms” instead of “AllForms”) as well as trying it in the subform itself rather than the form and doing so on different events, such as On_Current() or On_Load(), but nothing has worked for me so far.
Any help that you could offer me would be greatly appreciated.
Reference the subform starting either with Me from the code module of the form, or Form, followed by the name of the form. You then have the name of the subform control, Form, to refer to the object contained, and finally and property of the contained form.
Or
Note that it is important to use the name of the subform control, not the name of the form contained.
This code would run on the parent form and a record would need to be selected on the subform.