Referencing a subform field in a Word Merge

  • Thread starter Thread starter Meryl
  • Start date Start date
M

Meryl

I have two tables & forms - donors and donations.
Donations is a subform within donors. There can be more
than one donation per donor.

Afer a new donation is entered, the user can print a
thank you note for the donation. Currently I have a
command button that will open Word and enter the donor's
address and salutation information into the letter.
However, I do not know how to reference the most recent
donation amount (from the donations subform) to insert
the donation amount in the letter as well.

Can you help with this?

Thanks in advance!
 
Meryl said:
I have two tables & forms - donors and donations.
Donations is a subform within donors. There can be more
than one donation per donor.

Afer a new donation is entered, the user can print a
thank you note for the donation. Currently I have a
command button that will open Word and enter the donor's
address and salutation information into the letter.
However, I do not know how to reference the most recent
donation amount (from the donations subform) to insert
the donation amount in the letter as well.

Are the records in the donations subform sorted? If they're
sorted by the donation date, then the most recent donation
would be the first or last record in the subform's recordset
(depending on whether they're sorted ascending or
descending). In this case, the amount of the most recent
could be obtained this way:

With Me.subformcontrol.Form.RecordsetClone
.MoveLast ' or MoveFirst
curLatestDonation = !DonationAmount
End With

If the subform records are not sorted by donation date, then
you will have to search the donations table to find the
correct data. Here's some air code to demonstrate one way
to it:
strSQL = "SELECT TOP 1 DonationAmount " _
& "FROM Donations " _
& "WHERE DonorID = " & Me.txtDonorID & " " _
& "ORDER BY DonationDate DESC"
Set rs = CurrentDb.OpenRecordset(strSQL)
curLatestDonation = rs!DonationAmount
rs.Close : Set rs = Nothing
 
Back
Top