VB to populate report from Form subform (1 Viewer)

Flint2048

Registered User.
Local time
Today, 08:57
Joined
Oct 30, 2017
Messages
12
Hello all,

This relates to a previous SOLVED post of mine and the use of a Form to show records based on an Action Table (previous post discussed email attachments).

The form (FActions) also has a subform (TLinks_subform) shown which allows Users to record references (record numbers) for associated "Linked" records from other tables.

The form has a print button that opens a report and prints the content of the current record fields to a PDF output. This largely works but now I want to include the subform records and append the names of any found (may be multiple links) to one of the text boxes in the printed report.

The code I'm playing with is as follows...

Private Sub Report_Open(Cancel As Integer)
' Add Links references for each any every linked file
Dim rs As DAO.Recordset
Dim strFile As String
Set rs = [Forms]![FActions]![TLinks_subform].Form.RecordsetClone
With rs
If Not (.BOF And .EOF) Then .MoveFirst
While Not .EOF
' Set file (linked record name)
strFile = Link
MsgBox strFile
If strFile <> "" Then
' add the link reference to textbox "text4" in report
Me.Text4 = Me.Text4 & strFile & ", "
End If
.MoveNext
Wend
.Close
End With
Set rs = Nothing
End Sub

The msgbox entry (for diagnostics) confirms that it is able to identify 3 linked records (the msgbox appears three times for my test record) but for some reason displays blank i.e. strfile ="".

Any suggestions on where I am going wrong would be gratefully appreciated.

:)
 

Ranman256

Well-known member
Local time
Today, 04:57
Joined
Apr 9, 2015
Messages
4,339
you make a report that looks like the form.
the report also has a subReport that uses the same query to pull its data.
subRpt is also linked to the master report.
 

Flint2048

Registered User.
Local time
Today, 08:57
Joined
Oct 30, 2017
Messages
12
Thanks Ranman256.

The report is built and works for the parent form. The data is linked in terms of the underlying query and records for the main form.

I don't know how to append one of the existing report's fields from the subform recordset.

Can I modify my existing code to achieve this? It seems quite close.
 

Flint2048

Registered User.
Local time
Today, 08:57
Joined
Oct 30, 2017
Messages
12
The linked master field on the main form is [Ref].

The Linked Child field on the subform [TLinks_subform] is [ARef].

These allow the records to be associated. The actual subform (table) field I am interested in is [Link] as seen above.
 

Users who are viewing this thread

Top Bottom