Home > front end >  populate text boxes on Access report from text boxes on form
populate text boxes on Access report from text boxes on form

Time:11-14

I'm trying to populate all the text boxes on the report with the data from the text boxes from a form. The names of the text boxes are the same on the form and on the report. I tried this, but I'm stuck:

Dim ctl As Control
For Each ctl In Me.Controls
    If ctl.ControlType = acTextBox Then
        ctl.ControlSource = "[Forms]![frmlisteannuelle]![ctl.name]"
    End If
Next

CodePudding user response:

If you want to set ControlSource property with reference to form control name by using report control name, concatenate the variable and include = sign. Consider:

ctl.ControlSource = "=[Forms]![frmlisteannuelle]![" & ctl.name & "]"

CodePudding user response:

Your code was almost there! It was just missing an equal sign at the start and a concatenation between the expression and the clt.Name value. Take a look:

Private Sub Report_Open(Cancel As Integer)
    Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acTextBox Then
            ctl.ControlSource = "=Forms![frmlisteannuelle]![" & ctl.Name & "]"
        End If
    Next
End Sub
  • Related