I'm going to ask a dumb question, but in a quick scan of this thread, I am not sure.
What is the name of the actual subform and what is the name of the subform control? It is possible that both the form and the control have the same name - which would be bad, exactly because of problems like this.
is correct if and only if frmOrderAddEquip is the name of the control. In post #6 you SEEM to suggest that frmOrderAddEquip is a child form, which - if true - is part of the problem.
So .Form. only comes after a control? As i honestly have no clue, i've just been sticking it in here and there and alternating whether or not i include it by if the compiler or runtime complain!
Well, i have put the initial verbiage into an image so we can see if that helps: Edit: I had to delete the link you had in your post that was copied over to my response...
No, that didn't. I will try deleting part of that which you wrote...
Code:
Private Sub AmountCharged_Exit(Cancel As Integer)
'If IDContractType = 4 (Cash Equivalent), then make an entry into tblTransaction for the amount
'tblOrder-IDPaymentMethod Cash Equivalent would be 1,2,3. Internal = 4 and >=5 are all funders
'
Dim lCustomer As Long
Dim dtDate As Date
Dim lType As Long
Dim dPmtDebit As Double
Dim dPmtCredit As Double
Dim dTaxDebit As Double
Dim dTaxCredit As Double
Dim sNotes As String
Dim dtNow As Date
Dim dTaxRate As Double
Dim sForm As String
With Forms!frmCustomerOverview!frmOrder.Form
lCustomer = .IDCustomer
dtDate = Date
'lType = depends on Select Case
dPmtDebit = .AmountCharged
dPmtCredit = 0
'dTaxDebit
dTaxCredit = 0
sNotes = "Created from ORDER INFORMATION form"
dtNow = Format(Now(), "mm/dd/yyyy hh:mm:ss")
End With
dTaxRate = Nz(DLookup("TaxRate", "tblOrder", "IDOrder = " & IDOrder), -1)
' If no taxRate then
If dTaxRate = -1 Then
MsgBox "Tax Rate not found. You will now be directed to means to look it up and enter it for the future!" & vbCrLf & vbCrLf & vbCrLf & vbCrLf & "Are you not excited???"
Call TaxRateEntry(Zip, IDOrder, IDCustomer)
dTaxRate = dPubTaxRate
End If
Nope, that wasn't successful. Let's see what happens if i mess with the initial wording-
And now i am honored to be able to thank everyone!
Properly placing the portion (too many words starting with a "p") of Form.Recordset.RecordCount in the Load event of the Parent form returns a viable value (with modification, actually for two subforms present) that gave me a working solution!!!
Well Hi there The_Doc_Man! Do you do this 24/7???
Parent: frmOrderCreate
Child: frmOrderAddEquip
Control (textbox that relies upon a record): GrossEquipmentCost
other control in child form being used to test: EquipmentRowCount
That last one should be renamed EquipmentRecordCount
(It's only since Access that i have not been including control identifiers in their names, as with years in Excel if it were a textbox i would always start the naming with tb as in tbEquipmentRecordCount, or a combobox was cbx, a checkbox was chb... I am trying to define the advantages of either style)
24/7? No, I just have windows of opportunity at irregular intervals, usually in between gaming sessions. And, lately, construction contractor visits for estimates for fence repair.
In the syntax you initially demonstrated, frmOrderAddEquip is wrong. You originally showed us...
Follow me on this, reading right to left: You are asking for the .Value (implied because it is the default property) ...
currently in control GrossEquipmentCost ...
found on whatever is the Form (the name of which does NOT enter into this discussion) ...
loaded into the control frmOrderAddEquip ... <============
that is found in frmOrderCreate ...
that is found as a member of the Forms collection.
The problem is simple: frmOrderAddEquip is NOT a control, it is the name of a form. But an object of that name doesn't appear among the controls that ARE found in form frmOrderCreate. That syntax misuses that control object, hence the error 428 (Object doesn't support...). One problem with Access is that its error messages sometimes become a bit narrow-minded. Which error you get will change from one expression to the next depending on exactly how the expression is evaluated in that context.
In cases where you offered that expression as an argument to a function, what happens is that the expression flags an error - but in the function cases, the error is signaled AND HANDLED in the context of the function. Which changes the error originally signaled to "the function's actual argument was, in effect, empty".
Thank you, i apologize for my lack of clarity! I try both ways when i run into any error, omitting .Form. and putting it in. I am absolutely clueless as to when it is proper to use it other than if either including it or omitting it solves a problem. I know that is pretty lame, but i am not sure how to look up the term ".Form." due to getting back masses of how to create a form and the like citations...
Thank you, i apologize for my lack of clarity! I try both ways when i run into any error, omitting .Form. and putting it in. I am absolutely clueless as to when it is proper to use it other than if either including it or omitting it solves a problem. I know that is pretty lame, but i am not sure how to look up the term ".Form." due to getting back masses of how to create a form and the like citations...
OK, I think Doc was trying to explain, but I'll have a go too.
When you add a subform to a form you are actually adding a subform control which is a container that has a SourceObject property. The SourceObject is the actual form you use as the subform.
Depending on how you add the subform to your main form, the subform control may or may not be named the same as the form used as its SourceObject. (ie if you use the wizard or if you just add a subform control manually from the controls menu)
This is important.
It is important because, to reference a subform in VBA from the main form, you must use the name of the subform control, not the name of the form used as its SourceObject (unless it is the same by coincidence). Additionally you are referencing the subform control's .Form property.
As an example:
You have main form named frmMain.
You have created another form that you want to use as a subform on frmMain and have named it frmSub.
1. With frmMain in design view you use the Wizard to add the subform - it creates a subform control called frmSub and its SourceObject is set to use frmSub (confusing!)
2. If, instead, you add a subform from the Controls menus (click the subform button and drag the area on frmMain where you want it to be) you will have just created an empty subform control with a generic name like Child0. You then manually set its SourceObject to frmSub and enter its LinkMasterFields and LinkChildFields properties.
frmSub has a textbox on it called txtName. You want to reference this in VBA from outside frmSub's own module.
For the example 1 above you would use:
Code:
Forms.frmMain.frmSub.Form.txtName
For example 2 it would be:
Code:
Forms.frmMain.Child0.Form.txtName
In both instances you are referencing the name of the subform control, and in both instances you must reference its .Form property to access the controls on the subform.
Personally I find it easier to give the subform control a name different from the form used as its SourceObject - that way I avoid confusion as to which object I am referring to.
Others prefer it when they are name the same. However, whichever path you go down, you must remember to reference the name of the subform control and access the subform's controls/properties via the subform control's .Form property.
To find out a subform control's name you must click the very edge of it in frmMain's design view, or drag your mouse pointer from outside the control over its edge and then release. Its name should show up in the control properties box. The little black square at the top left of the contained form should not be visible - if it is, then you have selected the actual form (frmSub) and not the subform control.
As always, re-reading these long explanations seems more confusing than helpful, but hopefully you'll get it and stop having to randomly try various combinations when referencing subforms and their controls!
So .Form. only comes after a control? As i honestly have no clue, i've just been sticking it in here and there and alternating whether or not i include it by if the compiler or runtime complain!