Search code examples
vbams-accessms-access-2013ms-access-formsms-access-reports

How to pull text from the selected TextBox on a Report? VBA


I have a Report (rptCourses) which contains 170 TextBoxes which contain Course names, pulled from an access Table (tblCourses). When the user clicks on one of the Course Name TextBoxes, a form (frmRateCourse) loads containing a TextBox (txtboxCourseTitle), essentially a header, which ideally would contain the Course Name of the selected Report TextBox.

My question is: How can I take the text from the selected Report Textbox and input that text into the loaded Form's TextBox?

I apologize if this question already exists! And thank you, in advance, for any assistance!


Solution

  • Easiest is to pass the string as OpenArgs.

    Private Sub CourseName_Click()
        DoCmd.OpenForm "frmRateCourse", OpenArgs:=Me.CourseName.Value
    End Sub
    

    and in frmRateCourse:

    Private Sub Form_Open(Cancel As Integer)
        Me.lbTitle.Caption = Nz(Me.OpenArgs, "<no Title>")
    End Sub