Reputation: 1
I've been trying to understand how to reference a subform control from a different module. Many forums have pointed to the following link: http://access.mvps.org/access/forms/frm0031.htm
I have not had success adding this to my code yet. Not sure that I'm missing.
From the first form, when the user clicks the command button the following code runs:
Private Sub Command3_Click()
policyid = Me.PolicyList
Call openpolicy(policyid)
End Sub
From Module1:
Public Sub openpolicy(policyid)
DoCmd.OpenForm ("frmPolicyDetails")
Dim dbs As DAO.Database
Dim rcd As DAO.Recordset
Set dbs = CurrentDb
Set rcd = dbs.OpenRecordset("Select * from Policy Inner join client on client.clientid = policy.clientid where Policy.id = " & policyid)
Forms!Frmpolicydetails.selectedpolicy = rcd("PolicyNumber")
Forms!Frmpolicydetails.selectedName = rcd("FirstName") & " " & rcd("LastName")
'Trying to update subform textbox
Forms!frmpolicydetails!frmpolicyInfo.policynumber = rcd("PolicyNumber")
End Sub
"FrmPolicyInfo" is the "target name" the navigation form points to and "PolicyNumber" is the name of the control on the subform
Any ideas?
Upvotes: 0
Views: 2917
Reputation: 12210
I'll give you one little tip that has helped me with this problem. You need to refer to the SubformControl (the box that contains the subform) and then to the form contained within it, and finally to the control.
Forms!MainFormName!SubformControlName.Form!txtControlName
So in your case it might look like this:
Forms!frmpolicydetails!SubformControl1.Form!policynumber = rcd("PolicyNumber")
The confusing part here is that you don't want to change ".Form!" to be your form name. When you refer to a subform control's form object, you always refer to it as Form, not the form's name.
Upvotes: 1