Referring to Control on a Subform

aziz rasul

Active member
Local time
Today, 10:47
Joined
Jun 26, 2000
Messages
1,935
I have a main form ("frmGeneralEnquiries") which contains a subform ("frmEnquirerSubformPrimary4") containing a textbox control (txtComments) and several checkboxes (e.g. uncontrolledbloodpressure).

As an example, using the checkbox given above, when there is a tick in the checkbox, I want to insert a comment in txtComments using code in a module.

The code in the Click event of the checkbox is: -

Code:
Private Sub uncontrolledbloodpressure_Click()

    If Me.uncontrolledbloodpressure = -1 Then
        Call CIComment(Forms!frmGeneralEnquiries.frmEnquirerSubformPrimary4.Form, "Uncontrolled Blood Pressure")
    End If

End Sub

I want to establish what is in txtComments for the record shown in the subform before adding new data in txtComments.

Code:
Public Sub CIComment(frm As Form, strComment As String)

    Dim strComments As String
    
    strComments = Forms(frm.Name).Controls("txtcomments")

End Sub

I get the run time error 2450 'can't find frmEnquirerSubformPrimary4'.
 
I would use this notation

Forms!frmGeneralEnquiries!frmEnquirerSubformPrimary4!txtcomments

assuming that the container for the subform (on the mainform) has the same name as the form
 
Last edited:
Thanks Dennisk.
 

Users who are viewing this thread

Back
Top Bottom